From patchwork Fri Sep 15 17:55:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 76160 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F281B3856954 for ; Fri, 15 Sep 2023 17:57:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F281B3856954 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694800621; bh=7U/Mxu1FlreC2aPvYyaZ2ekPPuxptoqHDhsT2TkmV+4=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=UOcVv8dE9UybYDRJdju+kasBk72mv8+d5YoFwXUgvo3o5Isqa1B0/kKmq0rcjo9LN eufgNBdmzNQ7kwuCNuD4CX0P56bf2lSYun41oFxmTEA8yzr1RezTJusXio6RYzTuTK Se/2C8a2IruzUBhE7DQzztSqTxbzIWY/BuVUqbFw= 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 A33DB3858288 for ; Fri, 15 Sep 2023 17:56:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A33DB3858288 Received: from mail-oa1-f70.google.com (mail-oa1-f70.google.com [209.85.160.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-BUy0AKIYNJeGCkxsvEh6Uw-1; Fri, 15 Sep 2023 13:56:25 -0400 X-MC-Unique: BUy0AKIYNJeGCkxsvEh6Uw-1 Received: by mail-oa1-f70.google.com with SMTP id 586e51a60fabf-1d6565a7ce9so2066421fac.1 for ; Fri, 15 Sep 2023 10:56:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694800584; x=1695405384; 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=7U/Mxu1FlreC2aPvYyaZ2ekPPuxptoqHDhsT2TkmV+4=; b=dXYyyvy0NtRJGsN2WCxQHI7cXQe7mZQHuPmqDV7Ua5jwplJxcAeIKebfN6GbLbwwq3 rcCENl6LkSCdb9mlcN2L33wusXEEq1/D+zPArXRjyJab6DXa16LjyvnV4s6KK4L/KU1Z YirxH1NpDt2lOCuO4Fgn0l8i0bvvIZm3G9xp1YqFR/oGwMB7yjPvsPqSY1KtMuGaemdd v0K6xr0ZmIUwrL5/fCWXYi+ECEKEFRE9QoXyrhaEv+B6ZszuVa0KNgx15uDo+Vjk3XjR +WXlZgtnDobhaGVPAT97+3llwlx4kdNvWdOk0TIYCXwl9sy8sdPSglDS+kRVnxC2p0zb e+Ww== X-Gm-Message-State: AOJu0YzSElfJ1D+SERqhlz766RwE/285szpAhi75JqS+wbP4IEgLC/wY l1cvAKLVnCK0AFKusryd2ohhuDOrWZpGbikICAIKUgw7JobQDmdmlH3IQp6GpC0qO6Ti6Na+RaU i2PF3UOaXj92/TM+iJwzG+xJ4BRZXsYQ1tinKlyG9g8mXdizEOsJR0dIN+nVqB06s/UGajw8Ekq Y= X-Received: by 2002:a05:6870:9188:b0:1d5:cdf7:bd95 with SMTP id b8-20020a056870918800b001d5cdf7bd95mr2454828oaf.16.1694800584759; Fri, 15 Sep 2023 10:56:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxcDzOsZXU/P9w7KdjrQlnq07jyt16jLrXXVVRegYJE0+nVW9glhiY/iVoGRhOork3Tt8mHw== X-Received: by 2002:a05:6870:9188:b0:1d5:cdf7:bd95 with SMTP id b8-20020a056870918800b001d5cdf7bd95mr2454807oaf.16.1694800584395; Fri, 15 Sep 2023 10:56:24 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id w25-20020a0ca819000000b0064f75162d49sm1437071qva.90.2023.09.15.10.56.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 10:56:24 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: constness of decltype of NTTP object [PR98820] Date: Fri, 15 Sep 2023 13:55:34 -0400 Message-ID: <20230915175534.2315315-1-ppalka@redhat.com> X-Mailer: git-send-email 2.42.0.216.gbda494f404 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.6 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_H4, RCVD_IN_MSPIKE_WL, 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.30 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/13? -- >8 -- This corrects decltype of a (class) NTTP object as per [dcl.type.decltype]/1.2 and [temp.param]/6 in the type-dependent case. In the non-dependent case (nontype-class8.C) we resolve the decltype ahead of time, and finish_decltype_type already made sure to drop the const VIEW_CONVERT_EXPR wrapper around the TEMPLATE_PARM_INDEX. PR c++/98820 gcc/cp/ChangeLog: * semantics.cc (finish_decltype_type): Drop cv-quals from the type of an NTTP object. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/nontype-class60.C: New test. --- gcc/cp/semantics.cc | 8 ++++++++ gcc/testsuite/g++.dg/cpp2a/nontype-class60.C | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class60.C diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 0f7f4e87ae4..a7ae5e78a6c 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -11599,6 +11599,14 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, case TEMPLATE_PARM_INDEX: expr = mark_type_use (expr); type = TREE_TYPE (expr); + if (VAR_P (expr) && DECL_NTTP_OBJECT_P (expr)) + { + /* decltype of an NTTP object is the type of the template + parameter, which never has cv-quals. */ + int quals = cp_type_quals (type); + gcc_checking_assert (quals & TYPE_QUAL_CONST); + type = cv_unqualified (type); + } break; case ERROR_MARK: diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class60.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class60.C new file mode 100644 index 00000000000..fb3a61cfe10 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class60.C @@ -0,0 +1,20 @@ +// PR c++/98820 +// { dg-do compile { target c++20 } } + +struct A { }; + +template +void f() { + static_assert(__is_same(decltype(V), A)); +} + +template +void g() { + static_assert(__is_same(decltype(V), A)); +} + +int main() { + constexpr A a; + f(); + g(); +}