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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTPS id C65A13858409 for ; Wed, 17 Nov 2021 19:52:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C65A13858409 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-553-UeAaudKGNS667cBTtdo2og-1; Wed, 17 Nov 2021 14:52:34 -0500 X-MC-Unique: UeAaudKGNS667cBTtdo2og-1 Received: by mail-qk1-f198.google.com with SMTP id o19-20020a05620a22d300b0046754380e8aso2798272qki.13 for ; Wed, 17 Nov 2021 11:52:34 -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=h0bubSFXUtNFzuxbrm/zrt19zL60etYzpOGEUzi/UXQ=; b=Z9CmsMy5QdDx3b55ukqNTO1fdK0fYIMbI5VDAiIr0uSuEZv/+/Xu3xf6saZOLTZiT3 g+vpEp6uztWKmCf1UXydCkpy1ls/4n1LO5VVDPFwTLFLjZQHQjZbifSSVVoCz9CoGioK LrRh057mkaCokFpc7MdL1tAgdWj5/D4aczsrLtyfuHP+YbDlTnIg7lRCQpzxO3z7iKqK t4pNF20Fe6hIj/iPzmESsxTn47BZwT40Sb3xDzv7rRmBqEy3582/GIxcqxIBHXLVMxH2 6Qd7CYufH70Z/Y0J+h5oUy3myxpBT5frPy9tFchXnlJKq/G6RPXnkv2JbuRUOAiJMkSk oQeA== X-Gm-Message-State: AOAM531fTscXWXGYp/eNWnK4CPLKA3jmgTrMtZlWS07581vFRV2DdGJn krXfVhYkuiU7PBXu0kKDznbEvs3KVSL45R7+aK1J6/8tVJ9MDVKWa6aoLRrptC59jO2jBcuFmUf jeCVhGMLVMKJK0rokQA== X-Received: by 2002:a37:654a:: with SMTP id z71mr16160491qkb.131.1637178753791; Wed, 17 Nov 2021 11:52:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDuFlMl8HQxH969v/hFyg7EKfTMMePhYTbAbr70QIH6WBXhw4SzP/WhAcyPTIIfSSFKM4Ttw== X-Received: by 2002:a37:654a:: with SMTP id z71mr16160464qkb.131.1637178753512; Wed, 17 Nov 2021 11:52:33 -0800 (PST) Received: from [192.168.1.130] (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id o20sm421734qkp.114.2021.11.17.11.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 11:52:33 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Wed, 17 Nov 2021 14:52:32 -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: Wed, 17 Nov 2021 19:52:37 -0000 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. > > > 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" } > > +} > > > >