From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 623E13858422; Fri, 19 Nov 2021 00:32:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 623E13858422 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5389] c++: implicit dummy object in requires clause [PR103198] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: 483092d3d996c52a16519261ecf4236ab1a2d99c X-Git-Newrev: 09c24fe42ff2cef3f3291f5a7540a5835c08430c Message-Id: <20211119003245.623E13858422@sourceware.org> Date: Fri, 19 Nov 2021 00:32:45 +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: Fri, 19 Nov 2021 00:32:45 -0000 https://gcc.gnu.org/g:09c24fe42ff2cef3f3291f5a7540a5835c08430c commit r12-5389-g09c24fe42ff2cef3f3291f5a7540a5835c08430c Author: Patrick Palka Date: Thu Nov 18 19:32:22 2021 -0500 c++: implicit dummy object in requires clause [PR103198] In the testcase below satisfaction misbehaves for f and g ultimately because find_template_parameters fails to notice that the constraint 'val.x' depends on the template parms of the class template. In contrast, satisfaction works just fine for h. The problem seems to come down to a difference in how any_template_parm_r handles 'this' vs a dummy object: it walks the TREE_TYPE of the former but not the latter, and this causes us to miss the tparm dependencies in f/g's constraints since in their case the implicit object parm through which we access 'val' is a dummy object. (For h, since we know it's a non-static member function when parsing its trailing constraints, the implicit object parm is 'this', not a dummy object.) This patch fixes this inconsistency by making any_template_parm_r walk into the TREE_TYPE of a dummy object, like it already does for 'this'. PR c++/103198 gcc/cp/ChangeLog: * pt.c (any_template_parm_r): Walk the TREE_TYPE of a dummy object. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-this1.C: New test. Diff: --- gcc/cp/pt.c | 5 +++++ gcc/testsuite/g++.dg/cpp2a/concepts-this1.C | 30 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 71a771fd0f2..6a2a9377648 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -10766,6 +10766,11 @@ any_template_parm_r (tree t, void *data) WALK_SUBTREE (TREE_TYPE (t)); break; + case CONVERT_EXPR: + if (is_dummy_object (t)) + WALK_SUBTREE (TREE_TYPE (t)); + break; + default: break; } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-this1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-this1.C new file mode 100644 index 00000000000..d717028201a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-this1.C @@ -0,0 +1,30 @@ +// PR c++/103198 +// { dg-do compile { target c++20 } } + +template +struct A { + T val; + + template + requires requires { val.x; } + void f(U); + + static void g(int) + requires requires { val.x; }; + + void h(int) + requires requires { val.x; }; +}; + +struct B { int x; }; +struct C { }; + +int main() { + A().f(0); + A().g(0); + A().h(0); + + A().f(0); // { dg-error "no match" } + A().g(0); // { dg-error "no match" } + A().h(0); // { dg-error "no match" } +}