https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124431
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Nathaniel Shead <[email protected]>: https://gcc.gnu.org/g:7b1a7720ef8a5f59e10c0f90211c75af91e42b90 commit r16-8024-g7b1a7720ef8a5f59e10c0f90211c75af91e42b90 Author: Nathaniel Shead <[email protected]> Date: Wed Mar 11 23:21:02 2026 +1100 c++/modules: Allow merging members of instantiations attached to named modules [PR124431] The crash in the linked PR occurs because we treat all entities attached to a (different) named module as being unmergeable, and so end up with two different FIELD_DECLs for the member of a type. But templates can be instantiated or specialised in any module, not just the module they originated from, but are still considered attached to that named module. It seems that we already handle class-scope VAR_DECL, FUNCTION_DECL, TYPE_DECL, and TEMPLATE_DECL correctly by using a MK_decl_spec or MK_type_spec merge kind, but FIELD_DECLs and CONST_DECLs are not depended upon separately and so never get MK_template_mask specs. For these cases I think we can always rely on the container being accurate and having its fields already setup, so this patch fixes the issue by allowing non-unique merge kind for decls with a template specialisation container of code TYPE_DECL. PR c++/124431 gcc/cp/ChangeLog: * module.cc (trees_in::key_mergeable): Allow merging members of template specialisations. gcc/testsuite/ChangeLog: * g++.dg/modules/merge-21_a.C: New test. * g++.dg/modules/merge-21_b.C: New test. * g++.dg/modules/merge-21_c.C: New test. * g++.dg/modules/merge-21_d.C: New test. Signed-off-by: Nathaniel Shead <[email protected]> Reviewed-by: Jason Merrill <[email protected]>
