From patchwork Tue Aug 6 17:03:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1969646 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Xx6T6d/b; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wdfmg6HFDz1ydt for ; Wed, 7 Aug 2024 03:04:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B21C83858416 for ; Tue, 6 Aug 2024 17:04:33 +0000 (GMT) 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.133.124]) by sourceware.org (Postfix) with ESMTP id 9E9AB3858C56 for ; Tue, 6 Aug 2024 17:04:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E9AB3858C56 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9E9AB3858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722963851; cv=none; b=Id/kUypiJerp1EXNzZ2CARWHrWuyuuI2XH9PSXMVJcVh0Sz3oQ3dn4g7hgSpDO2EaWGkmjiTceFzgYSOL8d2W3uEXRUxy1TN87oaoF+NmGqMw/lB/KFNvRCBBdKSZftIaVR5lOJEu+8DYuR0XZSRbGHhUuwyrmEJTL3y3Yq+ubA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722963851; c=relaxed/simple; bh=HmKhuA1R1lwsWLVfEu/JHC9LZ2UBAKIahcRbTkA+rXY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZZJH2a62ZmCchYf/gDMtlBCD2pCNu9AlUsp8K9cda9BXKD9levEfi1YiRPpC3qL495KKTAqRlHRUtVNTlFrDL8Qa3Dizse6cUX3k7R2+yWtA0PBO+UYB2wXkPM/js/rbKG75hPS/FJI9gxe/NgrgHUR/Ip+plJtoWiGam0Dzzj4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722963849; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=66GiBVsEAqmHdIwT4fq6UJaxafRH9SnL0hgHl+8Bzw4=; b=Xx6T6d/bkakkecDtewZ4hi3xLUbKXixVUzRGskRVHwBH6MjrNFA+BP7iv7YypBiLePXqzU MLyvhHbW7BTodqtbpqlXoiWcwiYVN/OZL1zu2CPi3CbX82rZwEWkkLPtHaoJf+IuQb8pUP LA7MBxzEuj6vaMRI20tFea6npW8fUMk= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-62-1L8XVlcsOPKB1Q9JLtX88A-1; Tue, 06 Aug 2024 13:04:07 -0400 X-MC-Unique: 1L8XVlcsOPKB1Q9JLtX88A-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-44fe92025d8so9730541cf.1 for ; Tue, 06 Aug 2024 10:04:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722963847; x=1723568647; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=66GiBVsEAqmHdIwT4fq6UJaxafRH9SnL0hgHl+8Bzw4=; b=D7UKqp7xROMG48qxPIX4mVmFVCvpjXqbkrjRC4HIMS7waSFHvTTHc5mQF46pXMVqBg yYpmI5XLnpKUIKv7IbIKXX2lVC4ZU6sfruIWG8RY6SCZ1QB74TnW7dAdNlsZk6dUb8E6 YIFS0IipMOZkQcgOxxImzEV825Wu1j9y0ALHr/+yFsjEblo0H1BImPGAp+kmqZ5PJcAa EXBMvwLmxzSqqPx94nXa6uKazOHRCUbou3cLVA5JTfb55Z5YFSDANvQtCtY2PfF5xbXT bQopS0wzhRtCgjrJ2652hRDq5GtakQD3eTH7xTXe5h+y27Anys2kP9KFr+EuFKaeNEi7 OmDg== X-Gm-Message-State: AOJu0YzojUIl1VL8Iz9ts9ZRoNDP/kw5pg9ih7STCU21PEzLounBf8ru qmxrUXOHt+9OqiV7rlVDiBhpzccFbtlu6Z9qu/k4ijNRS5ZVt2B8QpkvR00SgQqo4pSzEjYhY/C s751uYq430WtZBlgoYo6sNVVTBgYVOrlX1njLfBY3Qpo7JS7w0M6jcTpwaA3cD/MhTkVykc4GeN HkoKG+zpYLMWznjgnzRMn/IjxQYSFEOiWd2NU= X-Received: by 2002:a05:622a:199b:b0:447:ef38:a8cb with SMTP id d75a77b69052e-45189322282mr179602051cf.39.1722963846963; Tue, 06 Aug 2024 10:04:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGlLAvHLLFR7gIUjyKuaiukweh8Nrjpe/jW5MbAil8AMnQZq4IRTrOatZ+xGgVzS0g3mPIsrQ== X-Received: by 2002:a05:622a:199b:b0:447:ef38:a8cb with SMTP id d75a77b69052e-45189322282mr179601451cf.39.1722963846291; Tue, 06 Aug 2024 10:04:06 -0700 (PDT) Received: from jason-thinkpadp1gen4i.rmtusma.csb (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4518a6ae6fesm39244671cf.17.2024.08.06.10.04.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 10:04:05 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: zero-init and class nttp [PR94568] Date: Tue, 6 Aug 2024 13:03:56 -0400 Message-ID: <20240806170403.1194160-1-jason@redhat.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 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: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- A zero-initializer should not reflect the constness of what it's initializing, as it does not for initializers with different syntax. This does have mangling implications for rare C++20 code, but it seems infeasable to make the mangling depend on -fabi-version while fixing the semantic bug, and C++20 is still experimental anyway. PR c++/94568 gcc/cp/ChangeLog: * init.cc (build_zero_init_1): Call cv_unqualified. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/nontype-class36.C: Remove xfail. * g++.dg/cpp2a/nontype-class37.C: Remove xfail. * g++.dg/cpp1z/nontype-auto26.C: New test. --- gcc/cp/init.cc | 3 ++ gcc/testsuite/g++.dg/cpp1z/nontype-auto26.C | 29 ++++++++++++++++++++ gcc/testsuite/g++.dg/cpp2a/nontype-class36.C | 2 +- gcc/testsuite/g++.dg/cpp2a/nontype-class37.C | 2 +- 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/nontype-auto26.C base-commit: 69093fd8aa682a1b906e80b3c5f10956e692b7c4 diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index de82152bd1d..20373d26988 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -173,6 +173,9 @@ build_zero_init_1 (tree type, tree nelts, bool static_storage_p, gcc_assert (nelts == NULL_TREE || TREE_CODE (nelts) == INTEGER_CST); + /* An initializer is unqualified. */ + type = cv_unqualified (type); + if (type == error_mark_node) ; else if (static_storage_p && zero_init_p (type)) diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype-auto26.C b/gcc/testsuite/g++.dg/cpp1z/nontype-auto26.C new file mode 100644 index 00000000000..9abe54ed974 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/nontype-auto26.C @@ -0,0 +1,29 @@ +// PR c++/94568 +// { dg-do compile { target c++20 } } + +struct A; +typedef int A::*MemPtr; + +struct B { MemPtr p; }; + +static constexpr MemPtr mp { }; + +template struct X { }; + +typedef X XB; +typedef X XB; + +struct C { int a[2]; }; +template struct D { }; + +constexpr const int i0 = 0; +constexpr const int i_{ }; + +static_assert (i0 == i_); + +// typedef D DC01; +// typedef D DC01; +typedef D DC01; + +// { dg-final { scan-assembler "_Z1f1DIXtl1CtlA2_iLi0ELi1EEEEE" } } +void f(DC01) {} diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class36.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class36.C index 8371eb96621..2e6d76cd43a 100644 --- a/gcc/testsuite/g++.dg/cpp2a/nontype-class36.C +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class36.C @@ -59,7 +59,7 @@ typedef X XB00p; typedef X XB00p; typedef X XB00p; typedef X XB00p; -typedef X XB00p; // { dg-bogus "conflicting declaration" "pr94568" { xfail *-*-* } } +typedef X XB00p; // { dg-bogus "conflicting declaration" "pr94568" } static const constexpr MemFuncPtr mfp0 = { 0 }; static const constexpr MemFuncPtr mfpn = { nullptr }; diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class37.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class37.C index f5e9826d243..dc054a9939a 100644 --- a/gcc/testsuite/g++.dg/cpp2a/nontype-class37.C +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class37.C @@ -77,4 +77,4 @@ typedef D DC01; typedef D DC01; typedef D DC01; typedef D DC01; -typedef D DC01; // { dg-bogus "conflicting declaration" "pr94567" { xfail *-*-* } } +typedef D DC01; // { dg-bogus "conflicting declaration" "pr94568" }