]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: lambda in constraint of lambda [PR119175]
authorJason Merrill <jason@redhat.com>
Wed, 9 Apr 2025 17:22:56 +0000 (13:22 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 10 Apr 2025 20:42:34 +0000 (16:42 -0400)
Here when we went to mangle the constraints of from<0>, the outer lambda has
no mangling scope, but the inner one was treated as having the outer one as
its scope.  And mangling the outer one means mangling its constraints, which
include the inner one.  So infinite recursion.

But a lambda closure type isn't a scope that anything should have for
mangling, the inner lambda should also have no mangling scope.

PR c++/119175

gcc/cp/ChangeLog:

* mangle.cc (decl_mangling_context): Look through lambda type.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-lambda23.C: New test.

(cherry picked from commit 39892d9618ee0f06dd09271589878b0df7b1e75d)

gcc/cp/mangle.cc
gcc/testsuite/g++.dg/cpp2a/concepts-lambda23.C [new file with mode: 0644]

index 556f0db4269afbc2fc37f57bf68b8676ae55bad9..fe8e5a0fa2888d4babc2488a4e3c80d7a4f6f5cc 100644 (file)
@@ -1049,6 +1049,12 @@ decl_mangling_context (tree decl)
       tree extra = LAMBDA_TYPE_EXTRA_SCOPE (TREE_TYPE (decl));
       if (extra)
        return extra;
+      tcontext = CP_DECL_CONTEXT (decl);
+      if (LAMBDA_TYPE_P (tcontext))
+       /* Lambda type context means this lambda appears between the
+          lambda-introducer and the open brace of another lambda (c++/119175).
+          That isn't a real scope; look further into the enclosing scope.  */
+       return decl_mangling_context (TYPE_NAME (tcontext));
     }
   else if (template_type_parameter_p (decl))
      /* template type parms have no mangling context.  */
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda23.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda23.C
new file mode 100644 (file)
index 0000000..f442120
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/119175
+// { dg-do compile { target c++20 } }
+
+template<int = 0>
+static void from() requires requires {
+  []<int> requires requires { [] {}; } {};
+}
+{}
+
+int main() {
+  from();
+}