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.129.124]) by sourceware.org (Postfix) with ESMTPS id 96C3D385BF83 for ; Thu, 18 Nov 2021 19:26:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 96C3D385BF83 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-323-xpHpVKX1Oe29Tns4rxWkcA-1; Thu, 18 Nov 2021 14:26:00 -0500 X-MC-Unique: xpHpVKX1Oe29Tns4rxWkcA-1 Received: by mail-qk1-f200.google.com with SMTP id p18-20020a05620a057200b00467bc32b45aso5802102qkp.12 for ; Thu, 18 Nov 2021 11:25:59 -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:cc:references:from:in-reply-to :content-transfer-encoding; bh=30CfG9t/rXvo7qoCzjqmeTy4aTHRqTpn71hL+d+zqP4=; b=4PciSRl2eydM0qGqe5e5t43+C3L0wcKU+a0yfn9YstIWaizE+n1hV4YnTkdQ8rZ5Pz tiMGbMZgF8lWmu+qU+wcY1i9LkKQPLintXm1tsAiMVW6zaAljNYSDtvxrPekY1l7Pfxg Hvx+j8Np5UvOv9jS6bQoqtbVb1zc44zw2z1d2zK9ZpEumpVVwKy20hV0I28PPLpB1Qc0 /ueS4x0fsNcdRxGdPWmhO/hh72S8ZVaiSznxRPqI+TzNhlT3RGky6LxivA9f33K8we0R pGcAxTI7l4HuVbxGOZ1osYupCzw2YZPHsyFDfv+GXlzy3kvCOo4Oj6u338Hgbn+NakCl ZmGw== X-Gm-Message-State: AOAM5315zEXHtUvcU8Fw8ls2wIdpY2y3/W1Jkgmg6qf4vGAYamF3nsqx tsJ4Jkpmdo/R1zDg1WQK2wZqhklhRKsgLoGhlXVZGkuvE7VdwEVpUt+Iqcuck+qrmS16HLOeemk eqLyy6iLAIY9i7JtfwA== X-Received: by 2002:ac8:7d8a:: with SMTP id c10mr28496968qtd.415.1637263558887; Thu, 18 Nov 2021 11:25:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJz6KlT4a1zxdWPDZgOU+N1/QgO8uubuBVgNrCgss0NA+5wsQAp/r/LPkgjYPm/xb3ZHrV5TKA== X-Received: by 2002:ac8:7d8a:: with SMTP id c10mr28496935qtd.415.1637263558579; Thu, 18 Nov 2021 11:25:58 -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 v15sm397971qkl.91.2021.11.18.11.25.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 18 Nov 2021 11:25:57 -0800 (PST) Message-ID: Date: Thu, 18 Nov 2021 14:25:57 -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 Cc: gcc-patches@gcc.gnu.org References: <20211112012529.1829478-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: 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_H4, RCVD_IN_MSPIKE_WL, 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:26:03 -0000 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? >> >>> 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" } >>> +} >>> >> >> >