https://gcc.gnu.org/g:4b84e561856599f82ce8f12a876ade388d5db330
commit r16-5300-g4b84e561856599f82ce8f12a876ade388d5db330 Author: Jason Merrill <[email protected]> Date: Fri Nov 14 17:52:57 2025 +0530 c++/modules: fix hash_map issue Building std.compat.cc was crashing for me because we would first get a pointer into imported_temploid_friends, then insert a new entry, causing the hash_map to expand, and then dereference the pointer into the former location of the hash table. Fixed by dereferencing the pointer before inserting rather than after. gcc/cp/ChangeLog: * module.cc (transfer_defining_module): Dereference pointer into hash_map before possible insertion. Diff: --- gcc/cp/module.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 1578674614e7..11b5242c55a8 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -21811,17 +21811,18 @@ transfer_defining_module (tree olddecl, tree newdecl) DECL_MODULE_IMPORT_P (old_inner) = false; } - if (tree *orig = imported_temploid_friends->get (newdecl)) + if (tree *p = imported_temploid_friends->get (newdecl)) { + tree orig = *p; tree &slot = imported_temploid_friends->get_or_insert (olddecl); if (!slot) - slot = *orig; - else if (slot != *orig) + slot = orig; + else if (slot != orig) /* This can happen when multiple classes declare the same friend function (e.g. g++.dg/modules/tpl-friend-4); make sure we at least attach to the same module. */ gcc_checking_assert (get_originating_module (slot) - == get_originating_module (*orig)); + == get_originating_module (orig)); } }
