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 4745E3858406 for ; Wed, 17 Nov 2021 18:36:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4745E3858406 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-272-3sBq5SfEMHiLk3Sxzz5HLw-1; Wed, 17 Nov 2021 13:36:32 -0500 X-MC-Unique: 3sBq5SfEMHiLk3Sxzz5HLw-1 Received: by mail-qk1-f198.google.com with SMTP id bq9-20020a05620a468900b004681cdb3483so2604662qkb.23 for ; Wed, 17 Nov 2021 10:36:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=+ym4ypTp2uwM8ewRgNHthw8OmAZ3F87eS2Qq/pkUxu0=; b=fU6vE8oNvuHkOHjcnOYvCqyCJKcdulY8rX2OeOsSaYh0qj2Dhq4fMj9JT1+z+cEbuR mAPMe44NG2kresMePpmalJn28sYC/shD92rHNA3zorxhDZJqo0HQDzWrZXDmJiFxUKx8 dBOtuV/NvfdSH/8sYNk4dGiCeOUI4Xyn98DLpm1nLCkPMmt7K8j4pEGOi/sIRJV00Zpc AtxJFDfP3G2OvE8jLABk4ZzYIE0KgRZsVr4Drz1H8o+vkdlkD28bWWXsE/QomniYIXZ6 yFnOdh5ysjS8PZIHikERjhoqOTsE4yNQf3VTkgU9OIPdiinP598280Q51otQrbtddCdY KCvw== X-Gm-Message-State: AOAM530JwmvxHqLXxvM3CxYRDm0KqRNU3xrCT8fAYuU27lhjyJZZ1GzK zb+b6nGOUodI+9gRnuwl44+NVkqQKm/Ks3BU3KA8qaIcxd3E2ufEBSxT4uSRbPjK8cZmkXcVsP7 anEmMyZgBVY6GjmzZYA== X-Received: by 2002:ac8:7f02:: with SMTP id f2mr18669339qtk.147.1637174191856; Wed, 17 Nov 2021 10:36:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPJLuCYEsZnkXfce6cacJlV0SYZLq7Eyb+b5b//FvE5/VupPX99bw7oXzxTuv6xWPwXzCATg== X-Received: by 2002:ac8:7f02:: with SMTP id f2mr18669305qtk.147.1637174191581; Wed, 17 Nov 2021 10:36:31 -0800 (PST) Received: from [192.168.1.149] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id c4sm282441qkf.122.2021.11.17.10.36.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 Nov 2021 10:36:31 -0800 (PST) Message-ID: Date: Wed, 17 Nov 2021 13:36:30 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.1 Subject: Re: [PATCH] c++: implicit dummy object in requires clause [PR103198] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20211112012529.1829478-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20211112012529.1829478-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, 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 18:36:36 -0000 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? > 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" } > +} >