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 r13-984] c++: cv-quals of dummy obj for non-dep memfn call [PR105637] Date: Fri, 3 Jun 2022 16:07:48 +0000 (GMT) [thread overview] Message-ID: <20220603160748.80CCF384144B@sourceware.org> (raw) https://gcc.gnu.org/g:44a5bd6d933d86ed988fc4695aa00f122cf83eb4 commit r13-984-g44a5bd6d933d86ed988fc4695aa00f122cf83eb4 Author: Patrick Palka <ppalka@redhat.com> Date: Fri Jun 3 12:06:59 2022 -0400 c++: cv-quals of dummy obj for non-dep memfn call [PR105637] In non-dependent23.C below we expect the Base::foo calls to resolve to the second, third and fourth overloads respectively in light of the cv-qualifiers of 'this' in each case. But ever since r12-6075-g2decd2cabe5a4f, the calls incorrectly resolve to the first overload at instantiation time. This happens because the calls to Base::foo are all deemed non-dependent (ever since r7-755-g23cb72663051cd made us ignore 'this' dependence when considering the dependence of a non-static memfn call), hence we end up checking the call ahead of time, using as the object argument a dummy object of type Base. Since this object argument is cv-unqualified, the calls in turn resolve to the unqualified overload of baseDevice. Before r12-6075 this incorrect result would just get silently discarded and we'd end up redoing OR at instantiation time using 'this' as the object argument. But after r12-6075 we now reuse this incorrect result at instantiation time. This patch fixes this by making maybe_dummy_object respect the cv-quals of (the non-lambda) 'this' when returning a dummy object. Thus, ahead of time OR using a dummy object will give us the right answer that's consistent with the instantiation time answer. An earlier version of this patch didn't handle 'this'-capturing lambdas correctly, which broke lambda-this22.C below. PR c++/105637 gcc/cp/ChangeLog: * tree.cc (maybe_dummy_object): When returning a dummy object, respect the cv-quals of 'this' if available. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/lambda/lambda-this22.C: New test. * g++.dg/template/non-dependent23.C: New test. Diff: --- gcc/cp/tree.cc | 30 +++++++++++++++++------ gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this22.C | 20 +++++++++++++++ gcc/testsuite/g++.dg/template/non-dependent23.C | 25 +++++++++++++++++++ 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index 2b9cb7e1c7b..c678e3b9c4c 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -4319,15 +4319,31 @@ maybe_dummy_object (tree type, tree* binfop) if (binfop) *binfop = binfo; - if (current_class_ref - /* current_class_ref might not correspond to current_class_type if - we're in tsubst_default_argument or a lambda-declarator; in either - case, we want to use current_class_ref if it matches CONTEXT. */ - && (same_type_ignoring_top_level_qualifiers_p - (TREE_TYPE (current_class_ref), context))) + /* current_class_ref might not correspond to current_class_type if + we're in tsubst_default_argument or a lambda-declarator; in either + case, we want to use current_class_ref if it matches CONTEXT. */ + tree ctype = current_class_ref ? TREE_TYPE (current_class_ref) : NULL_TREE; + if (ctype + && same_type_ignoring_top_level_qualifiers_p (ctype, context)) decl = current_class_ref; else - decl = build_dummy_object (context); + { + /* Return a dummy object whose cv-quals are consistent with (the + non-lambda) 'this' if available. */ + if (ctype) + { + int quals = TYPE_UNQUALIFIED; + if (tree lambda = CLASSTYPE_LAMBDA_EXPR (ctype)) + { + if (tree cap = lambda_expr_this_capture (lambda, false)) + quals = cp_type_quals (TREE_TYPE (TREE_TYPE (cap))); + } + else + quals = cp_type_quals (ctype); + context = cp_build_qualified_type (context, quals); + } + decl = build_dummy_object (context); + } return decl; } diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this22.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this22.C new file mode 100644 index 00000000000..8c6afe06cac --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this22.C @@ -0,0 +1,20 @@ +// PR c++/105637 +// { dg-do compile { target c++11 } } + +struct Base { + void foo(); // #1 + void foo() const = delete; // #2 +}; + +template<class T> +struct TopClass : T { + void failsToCompile() { + [this] { Base::foo(); }(); // should select #2, not #1 + } + + void failsToCompile() const { + [this] { Base::foo(); }(); // { dg-error "deleted" } + } +}; + +template struct TopClass<Base>; diff --git a/gcc/testsuite/g++.dg/template/non-dependent23.C b/gcc/testsuite/g++.dg/template/non-dependent23.C new file mode 100644 index 00000000000..885a641a655 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/non-dependent23.C @@ -0,0 +1,25 @@ +// PR c++/105637 + +struct Base { + void foo(); // #1 + void foo() const; // #2 + void foo() volatile; // #3 + void foo() const volatile; // #4 +}; + +template<class T> +struct TopClass : T { + void failsToCompile() const { + Base::foo(); // should select #2, not #1 + } + + void failsToCompile() volatile { + Base::foo(); // should select #3, not #1 + } + + void failsToCompile() const volatile { + Base::foo(); // should select #4, not #1 + } +}; + +template struct TopClass<Base>;
reply other threads:[~2022-06-03 16:07 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=20220603160748.80CCF384144B@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).