]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/62255 (Introducing an unrelated template parameter causes compilation to...
authorJason Merrill <jason@redhat.com>
Thu, 26 Feb 2015 02:43:58 +0000 (21:43 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 26 Feb 2015 02:43:58 +0000 (21:43 -0500)
PR c++/62255
* pt.c (instantiate_decl): Handle recursive instantiation of
static data member.

From-SVN: r220997

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/template/recurse4.C [new file with mode: 0644]

index 30b1c3f24fd109c08c3a8d6db608d784c1a85556..44f5c0d746d6c6166ec44a7a2c73537dcedd73e9 100644 (file)
@@ -1,5 +1,9 @@
 2015-02-25  Jason Merrill  <jason@redhat.com>
 
+       PR c++/62255
+       * pt.c (instantiate_decl): Handle recursive instantiation of
+       static data member.
+
        * decl.c (begin_destructor_body): Condition clobber on
        -flifetime-dse.
 
index 2abfc70ef6dfdf7c223d2474a1218e1ff5432ea0..fc8300ae2a7b06e8942e47bf69d241bb69c365fd 100644 (file)
@@ -19794,13 +19794,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);
+           }
          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 (file)
index 0000000..ee8d1b7
--- /dev/null
@@ -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;