From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 8660D38515F5; Wed, 16 Jun 2021 21:29:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8660D38515F5 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-1543] c++: static memfn from non-dependent base [PR101078] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/master X-Git-Oldrev: cfe0a2ec26867b290eb84af00317e60f8b67455c X-Git-Newrev: 6816a44dfe1b5fa9414490a18a4aa723b6f38f18 Message-Id: <20210616212900.8660D38515F5@sourceware.org> Date: Wed, 16 Jun 2021 21:29:00 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Jun 2021 21:29:00 -0000 https://gcc.gnu.org/g:6816a44dfe1b5fa9414490a18a4aa723b6f38f18 commit r12-1543-g6816a44dfe1b5fa9414490a18a4aa723b6f38f18 Author: Jason Merrill 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 PR c++/91706 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 d4bb5cc5eaf..15947b2c812 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -16249,8 +16249,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, nullptr, 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 +struct B : private A { + struct C { + void g() { f(); } + void g2() { B::f(); } + }; +}; + +int main() { + B::C().g(); +}