]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: local class in nested generic lambda [PR109241]
authorJason Merrill <jason@redhat.com>
Wed, 22 Mar 2023 20:11:47 +0000 (16:11 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 26 Apr 2023 21:16:22 +0000 (17:16 -0400)
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

index e1c272b9817eabd8c25f9a3f6297bdfa5f9340f2..93a055c66a1ece053bf38bb236e50341617d075b 100644 (file)
@@ -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))