From patchwork Thu Feb 9 18:17:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 55061 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp494500wrn; Thu, 9 Feb 2023 10:18:12 -0800 (PST) X-Google-Smtp-Source: AK7set9dIpizcOYYTPZuTH1Ue8Uxovk2ilG90slb0l34p0aKgtRv5cvAw+azK2fc0Q9pMKxJoiJB X-Received: by 2002:a50:8d5b:0:b0:49e:28c1:936c with SMTP id t27-20020a508d5b000000b0049e28c1936cmr13733490edt.26.1675966692613; Thu, 09 Feb 2023 10:18:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675966692; cv=none; d=google.com; s=arc-20160816; b=ouFrLK3u/ScojiEKq0olq3kPaw9tWfsTeYk+UtJ4D7OEVZXyl4ioxyq98OoHZeFqb1 ivRAT29rvSKmVQG8N45cbuEIKyGWxK6EKy5IODqLI+SMgjvi5rGuGjbuT2rpTQ1ID5DW mxngl9OkI1pyWrKpFM+U1TZR6scABSazmee8pufZbGOh1iSzlOd77RA0SRXBTHdFp0vY 1+OZJx2BP32dC6YhwTe8mTcwv8DJYLbzgwvJUlaL1pS88yed+LQXFhz6n9OxL74tZgIm fQP80L8gpqBfIi6TsYooedzG/hyLMK60xYc/5pX2oa5iN8mwjGVB1mPuHsCU5DEVJDJN jyTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=8wvnc0My93ohEDmNGIXwNv56YLxKoxN9tDKa6UUAfyo=; b=cluf74hH5xzhC7W+6LxYtVqCc/6nevq10dSlumCtbhNNobCiBpqVpWRt2qlnJUuhXl T32YfgnnEWNpCGt8OmlCiuZl+96ETPmUVvnH4xW7lbmSlcSj2LS4g7kec/vjjLM6SDea Cj2gRcTym8+alH/9cN+WAlQ0WXO3ehNsaQi301ks6Bd7jkwy4JzNC2769kUE3gwc9MsM UP3vNceqtGqDt1Qcx9QAVuJicAJL1FqZ2wypXunt3opYMI50a4l8Iy94rncmoSB8e5HB JPcVijZ1iJaLwoHAUfCVsMsY4VtKo8+0dyRNN+7k53tpCv+oIRMd65rurc92kJY6/DTI Yk0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uPGYFyne; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b1-20020aa7c901000000b004aac68c543csi2958547edt.507.2023.02.09.10.18.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 10:18:12 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uPGYFyne; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 62C973858025 for ; Thu, 9 Feb 2023 18:18:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 62C973858025 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675966691; bh=8wvnc0My93ohEDmNGIXwNv56YLxKoxN9tDKa6UUAfyo=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=uPGYFynefwnybkVQKdtlx8P4LZlt3chnz0C7gspZTMucBAcWJaAQbYtPp54w1QuNS Q3XV/FOQJyhqksVG/LGSx+KBSfkRqMN+s0mQ8htRR95TeJYSSbLUhAcKPALIfMr3jh oM/nkvt936Of170V63C/chJSHcMVI6v0tKG3EmGo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 138053858C62 for ; Thu, 9 Feb 2023 18:17:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 138053858C62 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-563-p-7NcAhkM3mncXRRTfBswQ-1; Thu, 09 Feb 2023 13:17:26 -0500 X-MC-Unique: p-7NcAhkM3mncXRRTfBswQ-1 Received: by mail-qv1-f69.google.com with SMTP id c10-20020a05621401ea00b004c72d0e92bcso1685630qvu.12 for ; Thu, 09 Feb 2023 10:17:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8wvnc0My93ohEDmNGIXwNv56YLxKoxN9tDKa6UUAfyo=; b=bj2Bo6KkPiZBSrI2kpdu3N40dBCftR+2MUA6OXtnKaN37QKVe6MPZBoa8C+hzhnE/M nG+C7d0mIEpVNvndrxvck+TF2geN0T+Xm9qF+AP+Z/7UZuYHqQi2kUIbUkbb6lpxvSX0 7fdS90Yiq2krgeOPvPLgKdLJThTfonochy+gmb+kkV8oAWmxwmGoH0ILQrbrkw3sYeK6 AhNOCX5XkiFrI6n3qofHaapCh9m8K2AuPODAR17WVwKCODwNI84ykFctH8fneaLDrDlD c3aoztX5DmKFq7znxind662sdy+FOQHQA5pofF2MBHkaTKsjcuTBeBD1cUrmwi5HHYUG srEQ== X-Gm-Message-State: AO0yUKVtw3z+WfNUATe9EbkfzXL4HFVA0u3fxhf18t/y3AjCJvpsL4cZ WVQUuoVFrvTnpGdzB0alRtbpDcYQpUwsTlHv6oWt5i28XD8blpzuPYh1HL7o1tjokO2yzj9XtLE HBtZNBMb5wzW/tx8r+bt/Kyy/GMQO5dn0KE0oz94fInkh2THWE0imKB3opxBYH8WYng5lGrt4 X-Received: by 2002:a05:6214:e41:b0:56b:7ec7:b158 with SMTP id o1-20020a0562140e4100b0056b7ec7b158mr21451155qvc.36.1675966644947; Thu, 09 Feb 2023 10:17:24 -0800 (PST) X-Received: by 2002:a05:6214:e41:b0:56b:7ec7:b158 with SMTP id o1-20020a0562140e4100b0056b7ec7b158mr21451111qvc.36.1675966644618; Thu, 09 Feb 2023 10:17:24 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id s6-20020a372c06000000b00727538eb831sm1872235qkh.86.2023.02.09.10.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 10:17:24 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: sizeof(expr) in non-templated requires-expr [PR108563] Date: Thu, 9 Feb 2023 13:17:22 -0500 Message-Id: <20230209181722.3178411-1-ppalka@redhat.com> X-Mailer: git-send-email 2.39.1.418.g7876265d61 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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, 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 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-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757378450490026481?= X-GMAIL-MSGID: =?utf-8?q?1757378450490026481?= 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. 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 | 25 ++++++------------- .../g++.dg/cpp2a/concepts-requires35.C | 14 +++++++++++ 2 files changed, 21 insertions(+), 18 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,25 +20652,14 @@ 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); - } + ++cp_unevaluated_operand; + ++c_inhibit_evaluation_warnings; + if (TYPE_P (op1)) + op1 = tsubst (op1, args, complain, in_decl); else - { - ++cp_unevaluated_operand; - ++c_inhibit_evaluation_warnings; - if (TYPE_P (op1)) - op1 = tsubst (op1, args, complain, in_decl); - else - op1 = tsubst_copy_and_build (op1, args, complain, in_decl); - --cp_unevaluated_operand; - --c_inhibit_evaluation_warnings; - } + 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); });