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 138053858C62 for ; Thu, 9 Feb 2023 18:17:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 138053858C62 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=1675966647; 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; bh=8wvnc0My93ohEDmNGIXwNv56YLxKoxN9tDKa6UUAfyo=; b=GorrxTrJBAa4bqLPXHvAlHI1q3DuQYei+PC2gdNPzdrZwAIUxuSB1g6RrCpxosCpDu/ewN cy/EmkpazBt54T83VBrEHcyW4qDNKE0NGvBRTdoK5duW9uYYV6ELwRiHjdwGQFRvyOmFYx 1Tb7nI1l+gtI9XrFjDKCfcGgK10hYkA= 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) From: Patrick Palka 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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); }); -- 2.39.1.418.g7876265d61