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);
--- /dev/null
+// 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;