public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r9-10180] c++: static memfn from non-dependent base [PR101078]
Date: Fri, 13 May 2022 20:10:13 +0000 (GMT)	[thread overview]
Message-ID: <20220513201013.969D7398545B@sourceware.org> (raw)

https://gcc.gnu.org/g:5b98dd6703aa1c4aa54de7b6079fd3dc39f7e66d

commit r9-10180-g5b98dd6703aa1c4aa54de7b6079fd3dc39f7e66d
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Jun 16 16:09:59 2021 -0400

    c++: static memfn from non-dependent base [PR101078]
    
    After my patch for PR91706, or before that with the qualified call,
    tsubst_baselink returned a BASELINK with BASELINK_BINFO indicating a base of
    a still-dependent derived class.  We need to look up the relevant base binfo
    in the substituted class.
    
            PR c++/101078
    
    gcc/cp/ChangeLog:
    
            * pt.c (tsubst_baselink): Update binfos in non-dependent case.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/template/access39.C: New test.

Diff:
---
 gcc/cp/pt.c                              | 15 +++++++++++++--
 gcc/testsuite/g++.dg/template/access39.C | 17 +++++++++++++++++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index b8aa7f8cb6a..b4d522b3769 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -15460,8 +15460,19 @@ tsubst_baselink (tree baselink, tree object_type,
 	fns = BASELINK_FUNCTIONS (baselink);
     }
   else
-    /* We're going to overwrite pieces below, make a duplicate.  */
-    baselink = copy_node (baselink);
+    {
+      /* We're going to overwrite pieces below, make a duplicate.  */
+      baselink = copy_node (baselink);
+
+      if (qualifying_scope != BINFO_TYPE (BASELINK_ACCESS_BINFO (baselink)))
+	{
+	  /* The decl we found was from non-dependent scope, but we still need
+	     to update the binfos for the instantiated qualifying_scope.  */
+	  BASELINK_ACCESS_BINFO (baselink) = TYPE_BINFO (qualifying_scope);
+	  BASELINK_BINFO (baselink) = lookup_base (qualifying_scope, binfo_type,
+						   ba_unique, NULL, complain);
+	}
+    }
 
   /* If lookup found a single function, mark it as used at this point.
      (If lookup found multiple functions the one selected later by
diff --git a/gcc/testsuite/g++.dg/template/access39.C b/gcc/testsuite/g++.dg/template/access39.C
new file mode 100644
index 00000000000..d941555577e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/access39.C
@@ -0,0 +1,17 @@
+// PR c++/101078
+
+struct A {
+  static void f();
+};
+
+template<class>
+struct B : private A {
+  struct C {
+    void g() { f(); }
+    void g2() { B::f(); }
+  };
+};
+
+int main() {
+  B<int>::C().g();
+}


                 reply	other threads:[~2022-05-13 20:10 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=20220513201013.969D7398545B@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@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).