]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Non-inline temploid friends should still be COMDAT [PR122819]
authorNathaniel Shead <nathanieloshead@gmail.com>
Sun, 7 Dec 2025 12:17:15 +0000 (23:17 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Tue, 23 Dec 2025 22:49:59 +0000 (09:49 +1100)
commitffd34b63c2c2c9f0f928d8da26df729eef50db20
tree8ab25669578e978dd87a465154521865dfa4fce8
parent6437f059af0ac0c709bef97db5890a4ff33b8a1d
c++: Non-inline temploid friends should still be COMDAT [PR122819]

Modules allow temploid friends to no longer be implicitly inline, as
functions defined in a class body will not be implicitly inline if
attached to a named module.

This requires us to clean up linkage handling a little bit, mostly by
replacing usages of 'DECL_TEMPLATE_INSTANTIATION' with
'DECL_TEMPLOID_INSTANTIATION' when determining if an entity has vague
linkage.

This caused the friend88.C testcase to miscompile however, as 'foo' was
incorrectly having 'DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION' getting
set because it was keeping its tinfo.

This is because 'non_templated_friend_p' was returning 'false', since
the function didn't have a primary template.  But that's expected I
think here, so fixed by also returning true for friend declarations
pushed into namespace scope, which still allows dependent nested friends
to be considered templated.

PR c++/122819

gcc/cp/ChangeLog:

* decl.cc (start_preparsed_function): Use
DECL_TEMPLOID_INSTANTIATION instead of
DECL_TEMPLATE_INSTANTIATION to check vague linkage.
* decl2.cc (vague_linkage_p): Likewise.
(c_parse_final_cleanups): Simplify condition.
* pt.cc (non_templated_friend_p): Namespace-scope friend
function declarations without a primary template are still
non-templated.
* semantics.cc (expand_or_defer_fn_1): Also check for temploid
friend functions.

gcc/testsuite/ChangeLog:

* g++.dg/modules/tpl-friend-22.C: New test.
* g++.dg/template/friend88.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/decl.cc
gcc/cp/decl2.cc
gcc/cp/pt.cc
gcc/cp/semantics.cc
gcc/testsuite/g++.dg/modules/tpl-friend-22.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/friend88.C [new file with mode: 0644]