]> gcc.gnu.org Git - gcc.git/commit
c++: Support lambdas attached to more places in modules [PR111710]
authorNathaniel Shead <nathanieloshead@gmail.com>
Fri, 16 Feb 2024 04:52:48 +0000 (15:52 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Thu, 29 Feb 2024 05:04:03 +0000 (16:04 +1100)
commit3685fae23bb00898749dfc155212c9c5cd3a0980
tree478deafad1636edbb6d681254219ab4e2df9359c
parentfd07a29e39f5347d6cef3e7042a32306f97a1719
c++: Support lambdas attached to more places in modules [PR111710]

The fix for PR107398 weakened the restrictions that lambdas must belong
to namespace scope. However this was not sufficient: we also need to
allow lambdas attached to FIELD_DECLs, PARM_DECLs, and TYPE_DECLs.

For field decls we key the lambda to its class rather than the field
itself. Otherwise we can run into issues when deduplicating the lambda's
TYPE_DECL, because when loading its context we load the containing field
before we've deduplicated the keyed lambda, causing mismatches; by
keying to the class instead we defer checking keyed declarations until
deduplication has completed.

Additionally, by [basic.link] p15.2 a lambda defined anywhere in a
class-specifier should not be TU-local, which includes base-class
declarations, so ensure that lambdas declared there are keyed
appropriately as well.

Because this now requires 'DECL_MODULE_KEYED_DECLS_P' to be checked on a
fairly large number of different kinds of DECLs, and that in general
it's safe to just get 'false' as a result of a check on an unexpected
DECL type, this patch also removes the tree checking from the accessor.

Finally, to handle deduplicating templated lambda fields, we need to
ensure that we can determine that two lambdas from different field decls
match, so we ensure that we also deduplicate LAMBDA_EXPRs on stream in.

PR c++/111710

gcc/cp/ChangeLog:

* cp-tree.h (DECL_MODULE_KEYED_DECLS_P): Remove tree checking.
(struct lang_decl_base): Update comments and fix whitespace.
* module.cc (trees_out::lang_decl_bools): Always write
module_keyed_decls_p flag...
(trees_in::lang_decl_bools): ...and always read it.
(trees_out::decl_value): Handle all kinds of keyed decls.
(trees_in::decl_value): Likewise.
(trees_in::tree_value): Deduplicate LAMBDA_EXPRs.
(maybe_key_decl): Also support lambdas attached to fields,
parameters, and types. Key lambdas attached to fields to their
class.
(trees_out::get_merge_kind): Likewise.
(trees_out::key_mergeable): Likewise.
(trees_in::key_mergeable): Support keyed decls in a TYPE_DECL
container.
* parser.cc (cp_parser_class_head): Start a lambda scope when
parsing base classes.

gcc/testsuite/ChangeLog:

* g++.dg/modules/lambda-7.h: New test.
* g++.dg/modules/lambda-7_a.H: New test.
* g++.dg/modules/lambda-7_b.C: New test.
* g++.dg/modules/lambda-7_c.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/cp-tree.h
gcc/cp/module.cc
gcc/cp/parser.cc
gcc/testsuite/g++.dg/modules/lambda-7.h [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/lambda-7_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/lambda-7_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/lambda-7_c.C [new file with mode: 0644]
This page took 0.063405 seconds and 5 git commands to generate.