summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2014-09-09 11:59:45 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2014-09-09 11:59:45 +0000
commit9e26d5243fc181aea0bd2d833422f262441ea928 (patch)
treeaccff89b25d5d74b30830f7bb127bc7d568bdca5
parentb34d8dac9cee076be76fb44b4e47aa6b9fff9056 (diff)
downloadgcc-9e26d5243fc181aea0bd2d833422f262441ea928.tar.gz
PR c++/62255
* pt.c (instantiate_decl): Handle recursive instantiation of static data member. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@215062 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/pt.c19
-rw-r--r--gcc/testsuite/g++.dg/template/recurse4.C18
3 files changed, 36 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 3d872313930..6447bc71795 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2014-09-08 Jason Merrill <jason@redhat.com>
+
+ PR c++/62255
+ * pt.c (instantiate_decl): Handle recursive instantiation of
+ static data member.
+
2014-09-05 Jason Merrill <jason@redhat.com>
PR c++/62659
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 5ea5a5854d8..38093ecd67d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -19996,13 +19996,18 @@ instantiate_decl (tree d, int defer_ok,
args,
tf_warning_or_error, NULL_TREE,
/*integral_constant_expression_p=*/false);
- /* Make sure the initializer is still constant, in case of
- circular dependency (template/instantiate6.C). */
- const_init
- = DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (code_pattern);
- cp_finish_decl (d, init, /*init_const_expr_p=*/const_init,
- /*asmspec_tree=*/NULL_TREE,
- LOOKUP_ONLYCONVERTING);
+ /* If instantiating the initializer involved instantiating this
+ again, don't call cp_finish_decl twice. */
+ if (!DECL_INITIAL (d))
+ {
+ /* Make sure the initializer is still constant, in case of
+ circular dependency (template/instantiate6.C). */
+ const_init
+ = DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (code_pattern);
+ cp_finish_decl (d, init, /*init_const_expr_p=*/const_init,
+ /*asmspec_tree=*/NULL_TREE,
+ LOOKUP_ONLYCONVERTING);
+ }
if (enter_context)
pop_nested_class ();
pop_nested_namespace (ns);
diff --git a/gcc/testsuite/g++.dg/template/recurse4.C b/gcc/testsuite/g++.dg/template/recurse4.C
new file mode 100644
index 00000000000..ee8d1b70df9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/recurse4.C
@@ -0,0 +1,18 @@
+// PR c++/62255
+
+// It's not clear whether this is well-formed; instantiating the
+// initializer of 'value' causes the instantiation of Derived, which in
+// turn requires the value of 'value', but the recursion ends there, so it
+// seems reasonable to allow it.
+
+template <typename T> struct Test {
+ template<typename X> static int check(typename X::Type*);
+ template<typename> static char check(...);
+ static const bool value = (sizeof(check<T>(0)) == sizeof(int));
+};
+template <int> struct Sink { };
+template <typename T> struct Derived : Sink<Test<Derived<T> >::value> {
+ typedef int Type;
+};
+
+Sink<Test<Derived<int> >::value> s;