c++: redeclared hidden friend take 2 [PR105852]
authorJason Merrill <jason@redhat.com>
Tue, 7 Jun 2022 01:49:06 +0000 (21:49 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 8 Jun 2022 21:29:54 +0000 (17:29 -0400)
commite057d454db4dcf48c22f75e57599f797d8e55baf
treeb9361d3ee16d047a7388b6a3f1a3b65be2f1edea
parent777a80af43eebb7506937cf04b54f17c4fce2b8e
c++: redeclared hidden friend take 2 [PR105852]

My previous patch for 105761 avoided copying DECL_TEMPLATE_INFO from a
friend to a later definition, but in this testcase we have first a
non-friend declaration and then a definition, and we need to avoid copying
in that case as well.  But we do still want to set new_template_info to
avoid GC trouble.

With this change, the modules dump correctly identifies ::foo as a
non-template function in tpl-friend-2_a.C.

Along the way I noticed that the duplicate_decls handling of
DECL_UNIQUE_FRIEND_P was backwards for templates, where we don't clobber
DECL_LANG_SPECIFIC (olddecl) with DECL_LANG_SPECIFIC (newdecl) like we do
for non-templates.

PR c++/105852
PR c++/105761

gcc/cp/ChangeLog:

* decl.cc (duplicate_decls): Avoid copying template info
from non-templated friend even if newdecl isn't a definition.
Correct handling of DECL_UNIQUE_FRIEND_P on templates.
* pt.cc (non_templated_friend_p): New.
* cp-tree.h (non_templated_friend_p): Declare it.

gcc/testsuite/ChangeLog:

* g++.dg/modules/tpl-friend-2_a.C: Adjust expected dump.
* g++.dg/template/friend74.C: New test.
gcc/cp/cp-tree.h
gcc/cp/decl.cc
gcc/cp/pt.cc
gcc/testsuite/g++.dg/modules/tpl-friend-2_a.C
gcc/testsuite/g++.dg/template/friend74.C [new file with mode: 0644]