]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Partially revert "Support lambdas attached to more places in modules" [PR118245]
authorNathaniel Shead <nathanieloshead@gmail.com>
Wed, 14 May 2025 10:49:22 +0000 (20:49 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Wed, 14 May 2025 20:47:50 +0000 (06:47 +1000)
r14-9232-g3685fae23bb008 broke the ABI for lambdas in base classes,
causing ICEs when different lambdas got given the same mangled name.

This patch reverts the parser.cc changes from that patch to restore the
old behaviour.  The properly fixed behaviour is available in GCC 15.1
with r15-7202-g8990070b4297b9, but that change was not suitable for
backporting.

PR c++/118245

gcc/cp/ChangeLog:

* parser.cc (cp_parser_class_head): Remove lambda scope when
parsing base classes.

gcc/testsuite/ChangeLog:

* g++.dg/modules/lambda-7_a.H: Expect the test to fail.
* g++.dg/modules/lambda-7_b.C: Likewise.
* g++.dg/modules/lambda-7_c.C: Likewise.
* g++.dg/cpp2a/lambda-uneval23.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
gcc/cp/parser.cc
gcc/testsuite/g++.dg/cpp2a/lambda-uneval23.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/lambda-7_a.H
gcc/testsuite/g++.dg/modules/lambda-7_b.C
gcc/testsuite/g++.dg/modules/lambda-7_c.C

index ae97ae5c5f59849d2267cebd705bf839ad015fd4..4a2c1f272a3adbce43103eea024a05bdf41c29ef 100644 (file)
@@ -27750,16 +27750,10 @@ cp_parser_class_head (cp_parser* parser,
   if (cp_lexer_next_token_is (parser->lexer, CPP_COLON))
     {
       if (type)
-       {
-         pushclass (type);
-         start_lambda_scope (TYPE_NAME (type));
-       }
+       pushclass (type);
       bases = cp_parser_base_clause (parser);
       if (type)
-       {
-         finish_lambda_scope ();
-         popclass ();
-       }
+       popclass ();
     }
   else
     bases = NULL_TREE;
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-uneval23.C b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval23.C
new file mode 100644 (file)
index 0000000..fa009f5
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/118245
+// { dg-do compile { target c++20 } }
+
+template<auto> struct Cask {};
+struct T1 : Cask<[]{}> {
+  Cask<[]{}> c{};
+};
index 5197114f76ca3ef1b965c34c42d8c53c1a27cc2c..842aedc5fd94973c087245fab20324c4c5f6b969 100644 (file)
@@ -1,4 +1,4 @@
 // { dg-additional-options "-fmodule-header -Wno-subobject-linkage" }
-// { dg-module-cmi {} }
+// { dg-ice "see PR c++/118245" { c++20 } }
 
 #include "lambda-7.h"
index 2d781e930678dc3232012c9fa6fc3971574f14d5..cd4d0f3aa659fc4d1451cc61b0ceb0cea919d35c 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-additional-options "-fmodules-ts -fno-module-lazy -Wno-subobject-linkage" }
+// { dg-xfail-if "see PR c++/118245" { c++20 } }
 // Test for ODR deduplication
 
 #include "lambda-7.h"
index f283681fa96c2cabf767f16caee718400d2d36cb..3fd159e08a7666118c3b630b7459f7628a167547 100644 (file)
@@ -1,5 +1,5 @@
-// { dg-module-do run }
 // { dg-additional-options "-fmodules-ts -fno-module-lazy -Wno-subobject-linkage" }
+// { dg-xfail-if "see PR c++/118245" { c++20 } }
 
 import "lambda-7_a.H";