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 r12-1272] c++: alias with same name as base fn [PR91706] Date: Tue, 8 Jun 2021 03:56:52 +0000 (GMT) [thread overview] Message-ID: <20210608035656.904C239450C5@sourceware.org> (raw) https://gcc.gnu.org/g:f07edb5d7f3e77218ec846a9382f7c1d23e67b71 commit r12-1272-gf07edb5d7f3e77218ec846a9382f7c1d23e67b71 Author: Jason Merrill <jason@redhat.com> Date: Fri Apr 16 11:13:40 2021 -0400 c++: alias with same name as base fn [PR91706] This is a bit complex. Looking up c<T> in the definition of D::c finds C::c, OK. Looking up c in the definition of E finds D::c, OK. Since the alias is not dependent, we strip it from the template argument, leaving using E = A<decltype(c<T>())>; where 'c' still refers to C::c. But instantiating E looks up 'c' again and finds D::c, which isn't a function, and sadness ensues. I think the bug here is looking up 'c' in D at instantiation time; the declaration we found before is not dependent. This seems to happen because baselink_for_fns gets BASELINK_BINFO wrong; it is supposed to be the base where lookup found the functions, C in this case. gcc/cp/ChangeLog: PR c++/91706 * semantics.c (baselink_for_fns): Fix BASELINK_BINFO. gcc/testsuite/ChangeLog: PR c++/91706 * g++.dg/template/lookup17.C: New test. Diff: --- gcc/cp/semantics.c | 6 ++++-- gcc/testsuite/g++.dg/template/lookup17.C | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index d08c1ddabf9..f506a239864 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3663,8 +3663,10 @@ baselink_for_fns (tree fns) cl = currently_open_derived_class (scope); if (!cl) cl = scope; - cl = TYPE_BINFO (cl); - return build_baselink (cl, cl, fns, /*optype=*/NULL_TREE); + tree access_path = TYPE_BINFO (cl); + tree conv_path = (cl == scope ? access_path + : lookup_base (cl, scope, ba_any, NULL, tf_none)); + return build_baselink (conv_path, access_path, fns, /*optype=*/NULL_TREE); } /* Returns true iff DECL is a variable from a function outside diff --git a/gcc/testsuite/g++.dg/template/lookup17.C b/gcc/testsuite/g++.dg/template/lookup17.C new file mode 100644 index 00000000000..b8571b9f1eb --- /dev/null +++ b/gcc/testsuite/g++.dg/template/lookup17.C @@ -0,0 +1,18 @@ +// PR c++/91706 +// { dg-do compile { target c++11 } } +// { dg-additional-options -g } + +template <bool> struct A; + +struct B { static constexpr bool g = false; }; + +struct C { + template <typename> static B c (); +}; + +template <class T> struct D : C { + using c = decltype (c<T>()); + using E = A<c::g>; +}; + +D<int> g;
reply other threads:[~2021-06-08 3:56 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=20210608035656.904C239450C5@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: linkBe 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).