public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-9826] c++: repeated friend template [PR101894]
@ 2022-04-12 20:14 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-04-12 20:14 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:ad4b23729b2e57676efb3d8313f4fc5300b94339
commit r11-9826-gad4b23729b2e57676efb3d8313f4fc5300b94339
Author: Jason Merrill <jason@redhat.com>
Date: Fri Apr 1 16:18:31 2022 -0400
c++: repeated friend template [PR101894]
Since olddecl isn't a definition, it doesn't get DECL_FRIEND_CONTEXT, so we
need to copy it from newdecl when we merge the declarations.
PR c++/101894
gcc/cp/ChangeLog:
* decl.c (duplicate_decls): Copy DECL_FRIEND_CONTEXT.
gcc/testsuite/ChangeLog:
* g++.dg/lookup/friend22.C: New test.
Diff:
---
gcc/cp/decl.c | 5 +++++
gcc/testsuite/g++.dg/lookup/friend22.C | 7 +++++++
2 files changed, 12 insertions(+)
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 491a03cd94f..8d7d71d0590 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -2273,6 +2273,9 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
for (parm = DECL_ARGUMENTS (old_result); parm;
parm = DECL_CHAIN (parm))
DECL_CONTEXT (parm) = old_result;
+
+ if (tree fc = DECL_FRIEND_CONTEXT (new_result))
+ SET_DECL_FRIEND_CONTEXT (old_result, fc);
}
}
@@ -2592,6 +2595,8 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
otherwise it is a DECL_FRIEND_CONTEXT. */
if (DECL_VIRTUAL_P (newdecl))
SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl));
+ else if (tree fc = DECL_FRIEND_CONTEXT (newdecl))
+ SET_DECL_FRIEND_CONTEXT (olddecl, fc);
}
else if (VAR_P (newdecl))
{
diff --git a/gcc/testsuite/g++.dg/lookup/friend22.C b/gcc/testsuite/g++.dg/lookup/friend22.C
new file mode 100644
index 00000000000..f52a7d7bad5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/friend22.C
@@ -0,0 +1,7 @@
+// PR c++/101894
+
+struct A
+{
+ template<int> friend void foo();
+ template<int> friend void foo() {}
+};
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-04-12 20:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12 20:14 [gcc r11-9826] c++: repeated friend template [PR101894] Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).