https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124390
--- 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:6f842384864ba6f8f1d630f846becb13f1efb0ab commit r16-8040-g6f842384864ba6f8f1d630f846becb13f1efb0ab Author: Nathaniel Shead <[email protected]> Date: Sun Mar 8 02:48:10 2026 +1100 c++/modules: Don't create bindings for hidden friends [PR124390] In r16-6343-gc368ea51b3bae27e3007b9bd89f6162c4c80259f we stopped walking attached decls for a DECL_MODULE_KEYED_DECLS_P entity during dependency gathering so that we didn't unnecessarily expose them if they weren't going to be emitted anyway, and relied on walking the definition to properly setup dependencies. But the linked PR shows that if those attached decls instantiate a template that pushes a hidden friend, they might be found anyway even if we don't find them via the function definition, because we see the hidden decls during add_binding_entity. Apart from causing this crash, walking these hidden decls is both pointless (hidden friends, if needed, will always be walked by their owning class type, and ADL does not need namespace-scope bindings to call them) and expensive, because this can cause a large swathe of other otherwise discarded GMF entities to be marked as reachable. This patch fixes the issue by not creating bindings for hidden friends. Perhaps no hidden entities should have bindings at all, but doing this causes make_dependency to break on the underlying alias decl for a purview DECL_LOCAL_DECL_P when considering additional bindings that need to be created, and I think we might need this to stay around so that we can properly merge these decls anyway (though I haven't investigated this yet). So this patch goes for a more minimal fix for now. PR c++/124390 gcc/cp/ChangeLog: * module.cc (depset::hash::add_binding_entity): Don't create bindings for hidden friends. gcc/testsuite/ChangeLog: * g++.dg/modules/friend-13.C: New test. Signed-off-by: Nathaniel Shead <[email protected]> Reviewed-by: Jason Merrill <[email protected]>
