]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/modules: Diagnose TU-local lambdas, give mangling scope to lambdas in concepts
authorNathaniel Shead <nathanieloshead@gmail.com>
Sun, 5 Jan 2025 12:45:05 +0000 (23:45 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Sat, 25 Jan 2025 00:35:43 +0000 (11:35 +1100)
commit4c01f40985eafccc3dd058441325b58009defd09
tree34ea40a95550589ac58335b6942ae2789c54513d
parent8990070b4297b913025d564293f97c0440622976
c++/modules: Diagnose TU-local lambdas, give mangling scope to lambdas in concepts

This fills in a hole left in r15-6378-g9016c5ac94c557 with regards to
detection of TU-local lambdas.  Now that LAMBDA_EXPR_EXTRA_SCOPE is
properly set for most lambdas we can use it to detect lambdas that are
TU-local.

CWG2988 suggests that lambdas in concept definitions should not be
considered TU-local, since they are always unevaluated and should never
be emitted. This patch gives these lambdas a mangling scope (though it
will never be actually used in name mangling).

PR c++/116568

gcc/cp/ChangeLog:

* cp-tree.h (finish_concept_definition): Adjust parameters.
(start_concept_definition): Declare.
* module.cc (depset::hash::is_tu_local_entity): Use
LAMBDA_EXPR_EXTRA_SCOPE to detect TU-local lambdas.
* parser.cc (cp_parser_concept_definition): Start a lambda scope
for concept definitions.
* pt.cc (tsubst_lambda_expr): Namespace-scope lambdas may now
have extra scope.
(finish_concept_definition): Split into...
(start_concept_definition): ...this new function.

gcc/testsuite/ChangeLog:

* g++.dg/modules/internal-4_b.C: Remove XFAIL, add lambda alias
testcase.
* g++.dg/modules/lambda-9.h: New test.
* g++.dg/modules/lambda-9_a.H: New test.
* g++.dg/modules/lambda-9_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/cp-tree.h
gcc/cp/module.cc
gcc/cp/parser.cc
gcc/cp/pt.cc
gcc/testsuite/g++.dg/modules/internal-4_b.C
gcc/testsuite/g++.dg/modules/lambda-9.h [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/lambda-9_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/lambda-9_b.C [new file with mode: 0644]