From: Jason Merrill <jason@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [pushed] c++: redeclared hidden friend [PR105761]
Date: Fri, 3 Jun 2022 13:44:31 -0400 [thread overview]
Message-ID: <20220603174431.2007386-1-jason@redhat.com> (raw)
Here, when we see the second declaration of f we match it with the first
one, copy over DECL_TEMPLATE_INFO, and then try to use it when parsing the
definition, leading to confusion.
Tested x86_64-pc-linux-gnu, applying to trunk.
PR c++/105761
gcc/cp/ChangeLog:
* decl.cc (duplicate_decls): Don't copy DECL_TEMPLATE_INFO
from a hidden friend.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/auto-fn64.C: New test.
---
gcc/cp/decl.cc | 12 ++++++++++--
gcc/testsuite/g++.dg/cpp1y/auto-fn64.C | 12 ++++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp1y/auto-fn64.C
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index e0d397d5a07..90b12d69414 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -2654,7 +2654,13 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
if (LANG_DECL_HAS_MIN (newdecl))
{
DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
- if (DECL_TEMPLATE_INFO (newdecl))
+ if (new_defines_function
+ && DECL_TEMPLATE_INFO (olddecl)
+ && DECL_UNIQUE_FRIEND_P (DECL_TEMPLATE_RESULT
+ (DECL_TI_TEMPLATE (olddecl))))
+ /* Don't copy template info from a non-template friend declaration
+ in a class template (PR105761). */;
+ else if (DECL_TEMPLATE_INFO (newdecl))
{
new_template_info = DECL_TEMPLATE_INFO (newdecl);
if (DECL_TEMPLATE_INSTANTIATION (olddecl)
@@ -2662,8 +2668,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
/* Remember the presence of explicit specialization args. */
TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl))
= TINFO_USED_TEMPLATE_ID (new_template_info);
+ DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
}
- DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
+ else
+ DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
}
if (DECL_DECLARES_FUNCTION_P (newdecl))
diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn64.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn64.C
new file mode 100644
index 00000000000..13f3175da45
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn64.C
@@ -0,0 +1,12 @@
+// PR c++/105761
+// { dg-do compile { target c++14 } }
+// { dg-additional-options -Wno-non-template-friend }
+
+template <class T>
+class X {
+ friend auto f(X);
+};
+
+struct Y : X<long> {
+ friend auto f(X) { return 0L; }
+};
base-commit: 1982fe2692b6c3b7f969ffc4edac59f9d4359e91
--
2.27.0
reply other threads:[~2022-06-03 17:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220603174431.2007386-1-jason@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).