https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118245
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Nathaniel Shead <nsh...@gcc.gnu.org>: https://gcc.gnu.org/g:8990070b4297b913025d564293f97c0440622976 commit r15-7202-g8990070b4297b913025d564293f97c0440622976 Author: Nathaniel Shead <nathanielosh...@gmail.com> Date: Thu Jan 23 19:22:04 2025 +1100 c++: Fix mangling of otherwise unattached class-scope lambdas [PR118245] This is a step closer to implementing the suggested changes for https://github.com/itanium-cxx-abi/cxx-abi/pull/85. Most lambdas defined within a class should have an extra scope of that class so that uses across different TUs are properly merged by the linker. This also needs to happen during template instantiation. While I was working on this I found some other cases where the mangling of lambdas was incorrect and causing issues, notably the testcase lambda-ctx3.C which currently emits the same mangling for the base class and member lambdas, causing mysterious assembler errors since r14-9232. One notable case not handled either here or in the ABI is what is supposed to happen with such unattached lambdas declared in member templates; see lambda-uneval22. I believe that by the C++ standard, such lambdas should also dedup across TUs, but this isn't currently implemented, and it's not clear exactly how such lambdas should mangle. Since this should only affect usage of lambdas in unevaluated contexts (a C++20 feature) this patch does not add an ABI flag to control this behaviour. PR c++/118245 gcc/cp/ChangeLog: * cp-tree.h (LAMBDA_EXPR_EXTRA_SCOPE): Adjust comment. * parser.cc (cp_parser_class_head): Start (and do not finish) lambda scope for all valid types. (cp_parser_class_specifier): Finish lambda scope after parsing members instead. * pt.cc (instantiate_class_template): Add lambda scoping. gcc/testsuite/ChangeLog: * g++.dg/abi/lambda-ctx3.C: New test. * g++.dg/cpp2a/lambda-uneval22.C: New test. * g++.dg/cpp2a/lambda-uneval23.C: New test. Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com> Reviewed-by: Jason Merrill <ja...@redhat.com>