]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/modules: unexported friend template
authorJason Merrill <jason@redhat.com>
Sat, 29 Mar 2025 12:56:09 +0000 (08:56 -0400)
committerJason Merrill <jason@redhat.com>
Sat, 29 Mar 2025 15:18:06 +0000 (11:18 -0400)
commiteb26b667518c951d06f3c51118a1d41dcdda8b99
tree4f4b7cd2200ec46a80fb45d9382aeacb3ab9c2cf
parent9018336252463ffed28f01badfdea2a3ca3ba5c8
c++/modules: unexported friend template

Here we were failing to match the injected friend declaration to the
definition because the latter isn't exported.  But the friend is attached to
the module, so we need to look for any reachable declaration in that module,
not just the exports.

The duplicate_decls change is to avoid clobbering DECL_MODULE_IMPORT_P on
the imported definition; matching an injected friend doesn't change that
it's imported.  I considered checking get_originating_module == 0 or
!decl_defined_p instead of DECL_UNIQUE_FRIEND_P there, but I think this
situation is specific to friends.

I removed an assert because we have a test for the same condition a few
lines above.

gcc/cp/ChangeLog:

* decl.cc (duplicate_decls): Don't clobber DECL_MODULE_IMPORT_P with
an injected friend.
* name-lookup.cc (check_module_override): Look at all reachable
decls in decl's originating module.

gcc/testsuite/ChangeLog:

* g++.dg/modules/friend-9_a.C: New test.
* g++.dg/modules/friend-9_b.C: New test.
gcc/cp/decl.cc
gcc/cp/name-lookup.cc
gcc/testsuite/g++.dg/modules/friend-9_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/friend-9_b.C [new file with mode: 0644]