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 9A1B03858CDB for ; Tue, 14 Feb 2023 23:02:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A1B03858CDB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676415779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pak9n/Voi+VYvSpzSyfiO5dVBByo/uWh2uBstW3Vn0M=; b=eKhQYNDb+miDQNR28G7pTvpc7nBYRmrzWUvRrVt3l6VvAKk+Xxty8WuGVH0di8fAeiSvts YL4h7uhWqgLgzAT72jwQdwUZjiT3glfgDyxuWHgAqMxtocqvymBCtXzJhajbYsG/zvg2Jf 2TqsQUKTLvAdrRS9NUnsnqsgzaeaEi0= 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.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-13-PtqrHS9qOMmWMWCMThQECg-1; Tue, 14 Feb 2023 18:02:58 -0500 X-MC-Unique: PtqrHS9qOMmWMWCMThQECg-1 Received: by mail-qk1-f200.google.com with SMTP id ay10-20020a05620a178a00b0072db6346c39so10460870qkb.16 for ; Tue, 14 Feb 2023 15:02:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pak9n/Voi+VYvSpzSyfiO5dVBByo/uWh2uBstW3Vn0M=; b=cqahCBEG7FuZVl/sEF8WMbJy9VajSpD7nAq2Bp9oJ26n32EQ2csX7GI3Vw2xkZ48Tb 10PMNrLGgF2fiwne+V6TOqz4WNtvcwCNBH/y355LD0zthjsyNHJMS7mFkl11QSE698Vd LSrTb4ViWCGOd/EvAKR2rARcOizpdDsinBN5nRme/Wq8PeAOJZKe+BJ85GLJNtojK2tP HZ7bdj+gcNAUatJfijvGfs0h0mIAOWgTO7q9l1tGGKr1DepA3d2OtT5HRVTKtA97Xb0o 2hkdVzibMICubnMNbaCJv0Qu1UrhcpxIRzgyOS+soSUMs7igl/3fMRw9W7j93nf0OpMB KJjQ== X-Gm-Message-State: AO0yUKVdEpZhhRxt7flM5+mQSpj1YaWqGJc1VFIeHKbbdgISl0epQ9po gSLXGmBpI9HmykpeHykCWNAmlSs4DwcQmG6nOc9ZnkkRziIhZTWq1vyjbViQY92OKbqgaVnw4DT MBy3GZY8Zg4SABAzrSw== X-Received: by 2002:ac8:5f8e:0:b0:3bb:7c6b:9cb6 with SMTP id j14-20020ac85f8e000000b003bb7c6b9cb6mr828500qta.17.1676415777660; Tue, 14 Feb 2023 15:02:57 -0800 (PST) X-Google-Smtp-Source: AK7set//DAe+l0Zn9cQnyxKSrZsznxc0xxnX5PyP1qQ5Z727fddue790HNh8OGusBWshRAC8jrfxrw== X-Received: by 2002:ac8:5f8e:0:b0:3bb:7c6b:9cb6 with SMTP id j14-20020ac85f8e000000b003bb7c6b9cb6mr828476qta.17.1676415777320; Tue, 14 Feb 2023 15:02:57 -0800 (PST) Received: from [192.168.1.108] (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 fu48-20020a05622a5db000b003b63a734434sm12002690qtb.52.2023.02.14.15.02.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Feb 2023 15:02:56 -0800 (PST) Message-ID: Date: Tue, 14 Feb 2023 18:02:55 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: Re: [PATCH] c++: sizeof(expr) in non-templated requires-expr [PR108563] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org References: <20230209181722.3178411-1-ppalka@redhat.com> <54df93ff-b7ff-4e2f-ce94-84643cde01fe@idea> From: Jason Merrill In-Reply-To: <54df93ff-b7ff-4e2f-ce94-84643cde01fe@idea> 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=-12.6 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_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2/9/23 10:22, Patrick Palka wrote: > On Thu, 9 Feb 2023, Patrick Palka wrote: > >> When substituting into sizeof(expr), tsubst_copy_and_build elides >> substitution into the operand if args is NULL_TREE, and instead >> considers the TREE_TYPE of the operand. But here the (templated) >> operand is a TEMPLATE_ID_EXPR with empty TREE_TYPE, so we can't elide >> substitution in this case. >> >> Contrary to the associated comment (dating back to r69130) substituting >> args=NULL_TREE should generally work since we do exactly that in e.g. >> fold_non_dependent_expr, and I don't see why the operand of sizeof would >> be an exception. So this patch just removes this special case. >> >> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for >> trunk? Diff generated with -w to ignore noisy whitespace changes. > > This time with -w actually passed to format-patch: OK. > -- >8 -- > > PR c++/108563 > > gcc/cp/ChangeLog: > > * pt.cc (tsubst_copy_and_build) : Remove > special case for empty args. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/concepts-requires35.C: New test. > --- > gcc/cp/pt.cc | 11 ----------- > gcc/testsuite/g++.dg/cpp2a/concepts-requires35.C | 14 ++++++++++++++ > 2 files changed, 14 insertions(+), 11 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires35.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 9f3fc1fa089..f21d28263d1 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -20652,16 +20652,6 @@ tsubst_copy_and_build (tree t, > op1 = TREE_TYPE (op1); > bool std_alignof = (TREE_CODE (t) == ALIGNOF_EXPR > && ALIGNOF_EXPR_STD_P (t)); > - if (!args) > - { > - /* When there are no ARGS, we are trying to evaluate a > - non-dependent expression from the parser. Trying to do > - the substitutions may not work. */ > - if (!TYPE_P (op1)) > - op1 = TREE_TYPE (op1); > - } > - else > - { > ++cp_unevaluated_operand; > ++c_inhibit_evaluation_warnings; > if (TYPE_P (op1)) > @@ -20670,7 +20660,6 @@ tsubst_copy_and_build (tree t, > op1 = tsubst_copy_and_build (op1, args, complain, in_decl); > --cp_unevaluated_operand; > --c_inhibit_evaluation_warnings; > - } > if (TYPE_P (op1)) > r = cxx_sizeof_or_alignof_type (input_location, > op1, TREE_CODE (t), std_alignof, > diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires35.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires35.C > new file mode 100644 > index 00000000000..2bb4b2b0b5d > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires35.C > @@ -0,0 +1,14 @@ > +// PR c++/108563 > +// { dg-do compile { target c++20 } } > + > +template > +struct foo { > + static constexpr T value = 0; > +}; > + > +template > +inline constexpr T foo_v = foo::value; > + > +static_assert(requires { sizeof(foo_v); }); > +static_assert(requires { requires sizeof(foo_v) == sizeof(int*); }); > +static_assert(requires { requires sizeof(foo_v) == sizeof(char); });