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 98C74385842C for ; Thu, 9 Feb 2023 18:22:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 98C74385842C 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=1675966958; 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: in-reply-to:in-reply-to:references:references; bh=jBqMW3R6L0u8zjHC1Bexy7VHI51s2aKytxveDS0kO8M=; b=c8HFyHtlewZiHSzq9AhT3IzDO4ttXndCAsZUrzQfFMoQj6gwdqo8YfiF6ZVK56ixrP8meA HVmnrC2sH1ompHR7IoN1eHJunBijklJHZl/6oHd3QO5K6fK59TEurdTsJJIc2m2+V3ZSzz ZDwJdMQDOA4EZDw6XHZlr8/CdsuEApU= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-564-s2kOsUjkMreUMhNEu6C0LQ-1; Thu, 09 Feb 2023 13:22:37 -0500 X-MC-Unique: s2kOsUjkMreUMhNEu6C0LQ-1 Received: by mail-qv1-f69.google.com with SMTP id f1-20020ad442c1000000b0056c228fa15cso1706887qvr.4 for ; Thu, 09 Feb 2023 10:22:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jBqMW3R6L0u8zjHC1Bexy7VHI51s2aKytxveDS0kO8M=; b=y9iZf60B46nG9JxbTR7zx8WzxQoSOmSP2+hQEThqZlWKykMM/YWbc6o0VrUSCv2t44 ge2HuovpakYFIx1a7RhtqYBEkW+pOEYVp4vi9K3OMD5vVEbb7WnKgAAEpKcH26WzLqiR 83kejg/xvVgNI4MCZt5Dy1w9bB87ZgS9v8wTSBGi1wCULSwwjGqi1aX5DnWYIf81e4ns hqW9TcCE00VRDeSTgzwNCWYRG6dlzayQY/NbQZLGvCdhcJ0xcAUCnhrZwEzc6WPucwpL iLC8AwvPaKJ5+6359Y2EnToByZPINoC2AOEwibq7GXpeIk6i10+wssbLvvd8IRQNRn3a WeBw== X-Gm-Message-State: AO0yUKWdbRfUZsVeMxwWuMg/MDnVFvkM+JCmp9/UQ0nfKy6/90UH93mk 5UtiKtEsQ/cyS4eOeOvPNLVlpnmT4NIWGBrj6BTDfxxfCOrNpRJRLb0nZrrAW5+olxr8hlPCsq2 y6+C2dZiV4vCGxz/TFg== X-Received: by 2002:ac8:7e8f:0:b0:3ae:4e47:52d7 with SMTP id w15-20020ac87e8f000000b003ae4e4752d7mr22221809qtj.38.1675966956946; Thu, 09 Feb 2023 10:22:36 -0800 (PST) X-Google-Smtp-Source: AK7set8NsGUkUfcNTe/utMPzoygQk6XoXJgX6NNtDy7gqe4cSmJ1JS1DS+RsqLWSavOAYG/bkfkVwA== X-Received: by 2002:ac8:7e8f:0:b0:3ae:4e47:52d7 with SMTP id w15-20020ac87e8f000000b003ae4e4752d7mr22221787qtj.38.1675966956703; Thu, 09 Feb 2023 10:22:36 -0800 (PST) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id n76-20020a37404f000000b00729b7d71ac7sm1837783qka.33.2023.02.09.10.22.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 10:22:36 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 9 Feb 2023 13:22:35 -0500 (EST) To: Patrick Palka cc: gcc-patches@gcc.gnu.org, jason@redhat.com Subject: Re: [PATCH] c++: sizeof(expr) in non-templated requires-expr [PR108563] In-Reply-To: <20230209181722.3178411-1-ppalka@redhat.com> Message-ID: <54df93ff-b7ff-4e2f-ce94-84643cde01fe@idea> References: <20230209181722.3178411-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=-13.9 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_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 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: -- >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); }); -- 2.39.1.418.g7876265d61