public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-6485] c++: dependent bases and 'this' availability [PR103831] Date: Tue, 11 Jan 2022 18:00:57 +0000 (GMT) [thread overview] Message-ID: <20220111180057.B5E3F385AC32@sourceware.org> (raw) https://gcc.gnu.org/g:0378f563b0321c44c4a9c98cf46d2a22b9160f76 commit r12-6485-g0378f563b0321c44c4a9c98cf46d2a22b9160f76 Author: Patrick Palka <ppalka@redhat.com> Date: Tue Jan 11 13:00:48 2022 -0500 c++: dependent bases and 'this' availability [PR103831] Here during satisfaction of B's constraints we're failing to reject the object-less call to the non-static member function A::size ultimately because satisfaction is performed in the (access) context of the class template B, which has a dependent base, and so the any_dependent_bases_p check within build_new_method_call causes us to not reject the call. (Subsequent constexpr evaluation of the call succeeds since the function is effectively static.) This patch fixes this by refining the any_dependent_bases_p check within build_new_method_call: if we're in a context where 'this' is unavailable, then we cannot resolve the implicit object regardless of the presence of a dependent base. So let's also check current_class_ptr alongside a_d_b_p. PR c++/103831 gcc/cp/ChangeLog: * call.c (build_new_method_call): Consider dependent bases only if 'this' is available. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-class3.C: New test. * g++.dg/template/non-dependent18.C: New test. Diff: --- gcc/cp/call.c | 2 +- gcc/testsuite/g++.dg/cpp2a/concepts-class3.C | 12 ++++++++++++ gcc/testsuite/g++.dg/template/non-dependent18.C | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 88ab23392d2..d4a07a7a9b3 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -11125,7 +11125,7 @@ build_new_method_call (tree instance, tree fns, vec<tree, va_gc> **args, we know we really need it. */ cand->first_arg = instance; } - else if (any_dependent_bases_p ()) + else if (current_class_ptr && any_dependent_bases_p ()) /* We can't tell until instantiation time whether we can use *this as the implicit object argument. */; else diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-class3.C b/gcc/testsuite/g++.dg/cpp2a/concepts-class3.C new file mode 100644 index 00000000000..68b50b71278 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-class3.C @@ -0,0 +1,12 @@ +// PR c++/103831 +// { dg-do compile { target c++20 } } + +struct A { + constexpr int size() { return 42; } // non-static +}; + +template<class T> + requires (T::size() == 42) // { dg-error "without object" } +struct B : T { }; + +template struct B<A>; // { dg-error "constraint" } diff --git a/gcc/testsuite/g++.dg/template/non-dependent18.C b/gcc/testsuite/g++.dg/template/non-dependent18.C new file mode 100644 index 00000000000..3e1556821a6 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/non-dependent18.C @@ -0,0 +1,19 @@ +// PR c++/103831 +// { dg-do compile { target c++11 } } + +struct A { + constexpr int size() { return 42; } // non-static +}; + +template<class T> +struct B : T { + static_assert(A::size() == 42, ""); // { dg-error "without object" } + + static int f() { + static_assert(A::size() == 42, ""); // { dg-error "without object" } + return A::size(); // { dg-error "without object" } + } + + int n = A::size(); + static const int m = A::size(); // { dg-error "without object" } +};
reply other threads:[~2022-01-11 18:00 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=20220111180057.B5E3F385AC32@sourceware.org \ --to=ppalka@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).