From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id BB8A43858422 for ; Thu, 18 Nov 2021 19:49:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BB8A43858422 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-406-Zszcdb3bNl2Rj4oKsDQ7DQ-1; Thu, 18 Nov 2021 14:49:53 -0500 X-MC-Unique: Zszcdb3bNl2Rj4oKsDQ7DQ-1 Received: by mail-qk1-f197.google.com with SMTP id m9-20020a05620a24c900b00467f2fdd657so5879666qkn.5 for ; Thu, 18 Nov 2021 11:49:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=WFfvN585Zuou0K6KsIi/VcZfTLGIETLm+TZqyr2AQZ0=; b=tTflq45sK0JwnsovS2iTmrjMiHeY/BYj3X/abekBTQ89aS0d/MFGr5tw7RhuEGi/VV 9VH8604PTqRkZgedhU/1XKbK5Jk4Tqaphr6F0AN+NU4n3XRbLjDYj40lAidk/dfg4nLj Dly/PmW4kTkDB/rlGRx+htfPOTMMeLqp6Fb01nZLAu+6lPzWKeDQB6C6xO1+iCLa5s1A KD29p+Py0kYI/xtkrW4uv9IRMGUQdIolqyei/HB1QaFZwrkOuXOVGeZlQeeFJanOf/AQ Zl5maaw9yuq3yGIVgNE7yCVmE7BkXoRfPzS0LfX2BXII/E6iuq8rDgA+UKhA5PT5iDEu R6Ow== X-Gm-Message-State: AOAM532YGL3FAxvQouUmQlo5q92sRyd8EZRTJOUSTPKFUEo5jheB0ZjR ZS48ESINaUYOpXHiLFUGXvMF6IVXJDOhCecCQ2oAiOlQREhq4WGYLtEly6LpEok6kL8nWXGw/vq Vp2NUrzKIyk0XnspxOQ== X-Received: by 2002:a05:6214:4007:: with SMTP id kd7mr68616624qvb.52.1637264992932; Thu, 18 Nov 2021 11:49:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJx0VkjNzCPOGMF7X8ancr1c2X0P6KIK7O9YO1DpTwrYPQDXsWkud7D96uRtWzv8Iknvc/Csgw== X-Received: by 2002:a05:6214:4007:: with SMTP id kd7mr68616588qvb.52.1637264992650; Thu, 18 Nov 2021 11:49:52 -0800 (PST) Received: from [192.168.1.130] (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id w8sm416490qtc.36.2021.11.18.11.49.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 11:49:52 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 18 Nov 2021 14:49:51 -0500 (EST) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: implicit dummy object in requires clause [PR103198] In-Reply-To: Message-ID: References: <20211112012529.1829478-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-16.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Nov 2021 19:49:56 -0000 On Thu, 18 Nov 2021, Jason Merrill wrote: > On 11/17/21 14:52, Patrick Palka wrote: > > On Wed, 17 Nov 2021, Jason Merrill wrote: > > > > > On 11/11/21 20:25, Patrick Palka wrote: > > > > 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 parameters 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: we walk 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 parameter > > > > 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 parameter is 'this' instead of a dummy object.) > > > > > > > > This patch fixes this inconsistency by making any_template_parm_r also > > > > walk into the TREE_TYPE of a dummy object, as is already done for > > > > 'this'. > > > > > > > > Bootstrapped and regtested on x86_64-pc-linux-gnu, also tested on > > > > cmcstl2 and range-v3, does this look OK for trunk and 11? > > > > > > > > PR c++/103198 > > > > > > > > gcc/cp/ChangeLog: > > > > > > > > * pt.c (any_template_parm_r): Walk the TREE_TYPE of a dummy > > > > object. > > > > > > Should we handle CONVERT_EXPR with the various casts in cp_walk_subtrees? > > > > This seems to work well too. But I'm not sure about doing this since > > IIUC cp_walk_subtrees is generally supposed to walk subtrees that are > > explicitly written in the source code, but when a CONVERT_EXPR > > corresponds to an implicit conversion then the target type doesn't > > explicitly appear anywhere. > > We could check is_dummy_object there as well? Ah I see, sorry for the misunderstanding. So wouldn't that mean cp_walk_subtrees will wal the TREE_TYPE of a dummy object but not the TREE_TYPE of 'this'? That seems like a weird inconsistency at first glance. > > > > > > > > gcc/testsuite/ChangeLog: > > > > > > > > * g++.dg/cpp2a/concepts-this1.C: New test. > > > > --- > > > > gcc/cp/pt.c | 5 ++++ > > > > gcc/testsuite/g++.dg/cpp2a/concepts-this1.C | 30 > > > > +++++++++++++++++++++ > > > > 2 files changed, 35 insertions(+) > > > > create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-this1.C > > > > > > > > diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c > > > > index 82bf7dc26f6..fa55857d783 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" } > > > > +} > > > > > > > > > > > > > >