public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-9438] c++: __func__ and local class DMI [PR105809]
@ 2023-04-18 20:46 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2023-04-18 20:46 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:dbd8af5d8f4568ed5683ae8aa15ccb330bbf74c0
commit r12-9438-gdbd8af5d8f4568ed5683ae8aa15ccb330bbf74c0
Author: Jason Merrill <jason@redhat.com>
Date: Thu Mar 16 15:35:15 2023 -0400
c++: __func__ and local class DMI [PR105809]
As in 108242, we need to instantiate in the context of the enclosing
function, not after it's gone.
PR c++/105809
gcc/cp/ChangeLog:
* init.cc (get_nsdmi): Split out...
(maybe_instantiate_nsdmi_init): ...this function.
* cp-tree.h: Declare it.
* pt.cc (tsubst_expr): Use it.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/constexpr-__func__3.C: New test.
Diff:
---
gcc/cp/cp-tree.h | 1 +
gcc/cp/init.cc | 27 ++++++++++++++++--------
gcc/cp/pt.cc | 6 ++++++
gcc/testsuite/g++.dg/cpp0x/constexpr-__func__3.C | 15 +++++++++++++
4 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index f3aa2481f99..8228a7b43f1 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -7056,6 +7056,7 @@ extern bool is_copy_initialization (tree);
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);
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index fdfaaf9b983..75dbfe112b5 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -561,18 +561,16 @@ perform_target_ctor (tree init)
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
@@ -644,8 +642,19 @@ get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain)
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)
{
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index a9c57e5d45a..a638d30cc7e 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -19102,6 +19102,8 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
/* 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
@@ -19109,6 +19111,10 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_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;
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-__func__3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-__func__3.C
new file mode 100644
index 00000000000..365a4e00c5f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-__func__3.C
@@ -0,0 +1,15 @@
+// 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>();
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-04-18 20:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-18 20:46 [gcc r12-9438] c++: __func__ and local class DMI [PR105809] Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).