]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/modules: Use containing type as key for all member lambdas [PR122310]
authorNathaniel Shead <nathanieloshead@gmail.com>
Sat, 18 Oct 2025 12:43:14 +0000 (23:43 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Tue, 28 Oct 2025 01:22:52 +0000 (12:22 +1100)
commitfc900b25fa353849649a6a221ead2da580408820
tree76f883adf11701531cf38a8d6a7badeb313b619d
parent18540d2241c3550e5368d342685f5fb3d1130a4d
c++/modules: Use containing type as key for all member lambdas [PR122310]

The ICE in the linked PR occurs because we first stream the lambda type
before its keyed decl has been streamed, but the key decl's type depends
on the lambda.  And so when streaming the key decl to check for an
existing decl to merge with, merging the key decl itself crashes because
its type has only been partially streamed.

This patch fixes the issue by generalising the existing FIELD_DECL
handling to any class member using the outermost containing TYPE_DECL as
its key type.  This way we can guarantee that the key decl has been
streamed before the lambda type is otherwise needed.

PR c++/122310

gcc/cp/ChangeLog:

* module.cc (get_keyed_decl_scope): New function.
(trees_out::get_merge_kind): Use it.
(trees_out::key_mergeable): Use it.
(maybe_key_decl): Key to the containing type for all members.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit 8212abbeffa69f143808e126f40c67f3eb7e7844)
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/lambda-12.h [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/lambda-12_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/lambda-12_b.C [new file with mode: 0644]