public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [pushed] c++: friend template matching [PR107484]
Date: Mon,  3 Apr 2023 23:22:48 -0400	[thread overview]
Message-ID: <20230404032248.2722677-1-jason@redhat.com> (raw)

Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

Here friend matching tries to find a matching non-template friend and fails,
so we mark the friend as a template specialization to be determined later.
Then cplus_decl_attributes tries again to find a matching function and gets
confused by DECL_TEMPLATE_INSTANTIATION without DECL_TEMPLATE_INFO.  But it
doesn't make sense for find_last_decl to be trying to match anything with
DECL_USE_TEMPLATE set; those are matched elsewhere.

	PR c++/107484

gcc/cp/ChangeLog:

	* decl2.cc (find_last_decl): Return early if DECL_USE_TEMPLATE.

gcc/testsuite/ChangeLog:

	* g++.dg/lookup/friend25.C: New test.
---
 gcc/cp/decl2.cc                        | 5 +++++
 gcc/testsuite/g++.dg/lookup/friend25.C | 9 +++++++++
 2 files changed, 14 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/lookup/friend25.C

diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 2b195e99997..9594be4092c 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -1613,6 +1613,11 @@ find_last_decl (tree decl)
 
   if (tree name = DECL_P (decl) ? DECL_NAME (decl) : NULL_TREE)
     {
+      /* Template specializations are matched elsewhere.  */
+      if (DECL_LANG_SPECIFIC (decl)
+	  && DECL_USE_TEMPLATE (decl))
+	return NULL_TREE;
+
       /* Look up the declaration in its scope.  */
       tree pushed_scope = NULL_TREE;
       if (tree ctype = DECL_CONTEXT (decl))
diff --git a/gcc/testsuite/g++.dg/lookup/friend25.C b/gcc/testsuite/g++.dg/lookup/friend25.C
new file mode 100644
index 00000000000..74cf5dc3431
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/friend25.C
@@ -0,0 +1,9 @@
+// PR c++/107484
+
+namespace qualified_friend_no_match {
+  void f(int);
+  template<typename T> void f(T*);
+  struct X {
+    friend void qualified_friend_no_match::f(double); // { dg-error "does not match any template" }
+  };
+}

base-commit: 59b4a555c3f1c3dba376da1c4886a9ea18ad208d
-- 
2.31.1


                 reply	other threads:[~2023-04-04  3:23 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=20230404032248.2722677-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).