* [pushed] c++: local class in nested generic lambda [PR109241]
@ 2023-03-23 3:23 Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-03-23 3:23 UTC (permalink / raw)
To: gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
In this testcase, the tree walk to look for bare parameter packs was
confused by finding a type with no TREE_BINFO. But it should be fine that
it's unset; we already checked for unexpanded packs at parse time.
I also tried doing the partial instantiation of the local class, which is
probably the long-term direction we want to go, but for stage 4 let's go
with this safer change.
PR c++/109241
gcc/cp/ChangeLog:
* pt.cc (find_parameter_packs_r): Handle null TREE_BINFO.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/lambda-generic-local-class2.C: New test.
---
gcc/cp/pt.cc | 12 ++++++++----
.../g++.dg/cpp1y/lambda-generic-local-class2.C | 13 +++++++++++++
2 files changed, 21 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-generic-local-class2.C
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 90bcaa78701..40deedc9ba9 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -4069,10 +4069,14 @@ find_parameter_packs_r (tree *tp, int *walk_subtrees, void* data)
case TAG_DEFN:
t = TREE_TYPE (t);
if (CLASS_TYPE_P (t))
- /* Local class, need to look through the whole definition. */
- for (tree bb : BINFO_BASE_BINFOS (TYPE_BINFO (t)))
- cp_walk_tree (&BINFO_TYPE (bb), &find_parameter_packs_r,
- ppd, ppd->visited);
+ {
+ /* Local class, need to look through the whole definition.
+ TYPE_BINFO might be unset for a partial instantiation. */
+ if (TYPE_BINFO (t))
+ for (tree bb : BINFO_BASE_BINFOS (TYPE_BINFO (t)))
+ cp_walk_tree (&BINFO_TYPE (bb), &find_parameter_packs_r,
+ ppd, ppd->visited);
+ }
else
/* Enum, look at the values. */
for (tree l = TYPE_VALUES (t); l; l = TREE_CHAIN (l))
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-local-class2.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-local-class2.C
new file mode 100644
index 00000000000..83856de1f41
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-local-class2.C
@@ -0,0 +1,13 @@
+// PR c++/109241
+// { dg-do compile { target c++14 } }
+// { dg-options "" } no pedantic
+
+void g() {
+ [](auto) {
+ [](auto) {
+ ({
+ struct A {};
+ });
+ };
+ }(1);
+}
base-commit: cd0c433e5faba9a18f64881cd761a53a530aa798
--
2.31.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* [pushed] c++: local class in nested generic lambda [PR109241]
@ 2023-04-26 21:16 Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-04-26 21:16 UTC (permalink / raw)
To: gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
The earlier fix for PR109241 avoided the crash by handling a type with no
TREE_BINFO. But we want to move toward doing the partial substitution of
classes in generic lambdas, so let's take a step in that direction.
PR c++/109241
gcc/cp/ChangeLog:
* pt.cc (instantiate_class_template): Do partially instantiate.
(tsubst_expr): Do call complete_type for partial instantiations.
---
gcc/cp/pt.cc | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index e1c272b9817..93a055c66a1 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -12086,7 +12086,8 @@ instantiate_class_template (tree type)
return error_mark_node;
if (COMPLETE_OR_OPEN_TYPE_P (type)
- || uses_template_parms (type))
+ || (uses_template_parms (type)
+ && !TYPE_FUNCTION_SCOPE_P (type)))
return type;
/* Figure out which template is being instantiated. */
@@ -19356,10 +19357,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
case TAG_DEFN:
tmp = tsubst (TREE_TYPE (t), args, complain, NULL_TREE);
- if (dependent_type_p (tmp))
- /* This is a partial instantiation, try again when full. */
- add_stmt (build_min (TAG_DEFN, tmp));
- else if (CLASS_TYPE_P (tmp))
+ if (CLASS_TYPE_P (tmp))
{
/* Local classes are not independent templates; they are
instantiated along with their containing function. And this
@@ -19368,6 +19366,12 @@ 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);
+ if (dependent_type_p (tmp))
+ {
+ /* This is a partial instantiation, try again when full. */
+ add_stmt (build_min (TAG_DEFN, tmp));
+ break;
+ }
tree save_ccp = current_class_ptr;
tree save_ccr = current_class_ref;
for (tree fld = TYPE_FIELDS (tmp); fld; fld = DECL_CHAIN (fld))
base-commit: 50d866038a910ceb9075b97295a12d77a8d09a3a
prerequisite-patch-id: 4ed1b4e9cbee2ce090bd119cbf47056c35aaeb57
prerequisite-patch-id: cd3a881f1b6cd3bca0064002d9a96f2f52c85a79
--
2.31.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-04-26 21:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-23 3:23 [pushed] c++: local class in nested generic lambda [PR109241] Jason Merrill
2023-04-26 21:16 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).