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: 140592 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1224105vqi; Fri, 15 Sep 2023 10:57:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4PPWTg/oE3pg6Nz093en7WYRXTmBJHdS2fBt/cx80qh45KGs6st8Eg4HVRhLytYjQ6gKK X-Received: by 2002:a17:907:2c62:b0:9a1:d1a0:41ad with SMTP id ib2-20020a1709072c6200b009a1d1a041admr3042733ejc.21.1694800649946; Fri, 15 Sep 2023 10:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694800649; cv=none; d=google.com; s=arc-20160816; b=qNlMm1QJN9Lx5SfXNMn3O0uH87e+1kkAF4es4JHUmUAsRM2lSb7U9/EiX6HIGifoDT eWAyZ5KRx6QlhoJs0XuiJIpwbpRk4uOlGXe5Cs5Ar11N0Ef4K+P8uAVPSvWRc+6S1KBz nCFhk2Iuu2d4bHgPIN4uUmxpzK3UJUa14VAw0NgMlxI0y/vq1+UwU3KBQPLaQ1etLLdG Z9G+B9j/7v1dvU9ujXCaG0L8o+9GrY9Flsk4t6usP7U6EH5xrcouEcbT88GvocPkittR 7C0+vdlzuQcJcHzau//Rdft74lE8gj48/0FZgzpv2bEsgqSc1ubca5t8WodoQ6SiL5TV GCrg== 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=7U/Mxu1FlreC2aPvYyaZ2ekPPuxptoqHDhsT2TkmV+4=; fh=1Hi9m88IqcWZGtfSxUrMGG+GBgL26N02X1SANXM6iTs=; b=swalqDEF7ACtZoxEfWBSdIjp5sH5FG6EXJmooHp/EpVLxW1i6zXb8ChBLoVvU5QjnH 0mz4hJNby50W0OOehyef8fduPgUQPBm9FyiZJy9cxvLyl3HeRBvXYY7LVMXE3NpDsoTm pi6PsDHcGtENWcAgBxvIcKWYIgbrfCypO/2QU80s9EHiqNuMBsQAmwkonNPdEvtezCfO MCyv4M0E3h8E2nvd4zolozurkdFgM07lCGBRayOEyVJspU6z1yNYwKyS26nYIhmix/e3 htNPU1+rhqIbGpjREWiA8yvixooBL2bOKLsRgId+NuBsh+9lfj5MHmHKM7c4u0sCr9YQ V+cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wndoGFRL; 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qk14-20020a1709077f8e00b009adc760a237si3519175ejc.532.2023.09.15.10.57.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 10:57:29 -0700 (PDT) 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=wndoGFRL; 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 305643856DD6 for ; Fri, 15 Sep 2023 17:57:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 305643856DD6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694800635; 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=wndoGFRLoM7gUG5ej0cUL+MPd95YbxAr88LYhMm30LWjdQAFDfQ7cKfMaGY104wJk /Fc2jMsgdbF36ZYIAC30m76L/WXzTLo+C/HjsOMhdfkCniPepTQ2Wrp+GMT73BTrb2 39IM0r3jNEc5umF6wBjom5+OsSZcOASZZ4Sd2CmY= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777127286203241698 X-GMAIL-MSGID: 1777127286203241698 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(); +}