extern tree build_zero_init (tree, tree, bool);
extern tree build_value_init (tree, tsubst_flags_t);
extern tree build_value_init_noctor (tree, tsubst_flags_t);
+extern tree maybe_instantiate_nsdmi_init (tree, tsubst_flags_t);
extern tree get_nsdmi (tree, bool, tsubst_flags_t);
extern tree build_offset_ref (tree, tree, bool,
tsubst_flags_t);
return init;
}
-/* Return the non-static data initializer for FIELD_DECL MEMBER. */
+/* Instantiate the default member initializer of MEMBER, if needed.
+ Only get_nsdmi should use the return value of this function. */
static GTY((cache)) decl_tree_cache_map *nsdmi_inst;
tree
-get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain)
+maybe_instantiate_nsdmi_init (tree member, tsubst_flags_t complain)
{
- tree init;
- tree save_ccp = current_class_ptr;
- tree save_ccr = current_class_ref;
-
- if (DECL_LANG_SPECIFIC (member) && DECL_TEMPLATE_INFO (member))
+ tree init = DECL_INITIAL (member);
+ if (init && DECL_LANG_SPECIFIC (member) && DECL_TEMPLATE_INFO (member))
{
init = DECL_INITIAL (DECL_TI_TEMPLATE (member));
location_t expr_loc
input_location = sloc;
}
}
- else
- init = DECL_INITIAL (member);
+
+ return init;
+}
+
+/* Return the non-static data initializer for FIELD_DECL MEMBER. */
+
+tree
+get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain)
+{
+ tree save_ccp = current_class_ptr;
+ tree save_ccr = current_class_ref;
+
+ tree init = maybe_instantiate_nsdmi_init (member, complain);
if (init && TREE_CODE (init) == DEFERRED_PARSE)
{
/* Closures are handled by the LAMBDA_EXPR. */
gcc_assert (!LAMBDA_TYPE_P (TREE_TYPE (t)));
complete_type (tmp);
+ tree save_ccp = current_class_ptr;
+ tree save_ccr = current_class_ref;
for (tree fld = TYPE_FIELDS (tmp); fld; fld = DECL_CHAIN (fld))
if ((VAR_P (fld)
|| (TREE_CODE (fld) == FUNCTION_DECL
&& DECL_TEMPLATE_INSTANTIATION (fld))
instantiate_decl (fld, /*defer_ok=*/false,
/*expl_inst_class=*/false);
+ else if (TREE_CODE (fld) == FIELD_DECL)
+ maybe_instantiate_nsdmi_init (fld, tf_warning_or_error);
+ current_class_ptr = save_ccp;
+ current_class_ref = save_ccr;
}
break;
--- /dev/null
+// PR c++/105809
+// { dg-do compile { target c++11 } }
+
+template<typename ss> void hh() { ss t; }
+
+template<int>
+int f(void)
+{
+ constexpr char const* cc = __func__;
+ struct j{ char const* kk=cc; };
+ hh<j>();
+ return 0;
+}
+
+int t = f<1>();