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: 1740089 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=MysgmyQg; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PCQ8N3g4Zz23jH for ; Fri, 10 Feb 2023 05:17:51 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EC811385800A for ; Thu, 9 Feb 2023 18:17:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC811385800A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675966668; bh=8wvnc0My93ohEDmNGIXwNv56YLxKoxN9tDKa6UUAfyo=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=MysgmyQgHbxrINkIFhrB0ywygbUmmM+nQpMcaEjorqcyvrT0OAlSF6go0LXUmA/di kYz84hIZbP645WaWUgb3DoL/7AasD/nVpuHj+RFUZUlv25tn8TLzU0zNUPtjqHluxx VR7Vpum4iM6PODo7bnTDfHHH9RQGXVhnxMynQJcc= 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-Google-Smtp-Source: AK7set8GIWLT+d+xby4WUr6wmVra6QXJMXdjKCJDz+lH8n+zrIjX6gAdJ/vKmb4wDxK4W1P7LTuBiw== 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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); });