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.133.124]) by sourceware.org (Postfix) with ESMTPS id 3BD3A3858C3A for ; Fri, 21 Jan 2022 13:21:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3BD3A3858C3A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-586-sKi23D_cN8G6Zu2PVYINRQ-1; Fri, 21 Jan 2022 08:21:50 -0500 X-MC-Unique: sKi23D_cN8G6Zu2PVYINRQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0CC1B84B9A4; Fri, 21 Jan 2022 13:21:50 +0000 (UTC) Received: from localhost (unknown [10.33.36.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id A17CA108F850; Fri, 21 Jan 2022 13:21:49 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix constexpr constructor for atomic> Date: Fri, 21 Jan 2022 13:21:48 +0000 Message-Id: <20220121132148.170509-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-13.9 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_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Jan 2022 13:21:58 -0000 Tested powerpc64le-linux, pushed to trunk. libstdc++-v3/ChangeLog: * include/bits/shared_ptr_atomic.h (_Sp_atomic::_Atomic_count): Add constexpr. (_Sp_atomic::_M_ptr): Add default member-initializer. * testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc: Check constant initialization. * testsuite/20_util/weak_ptr/atomic_weak_ptr.cc: Likewise. --- libstdc++-v3/include/bits/shared_ptr_atomic.h | 4 ++-- .../testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc | 3 +++ libstdc++-v3/testsuite/20_util/weak_ptr/atomic_weak_ptr.cc | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/bits/shared_ptr_atomic.h b/libstdc++-v3/include/bits/shared_ptr_atomic.h index 35f781dc9a0..9e4df7da7f8 100644 --- a/libstdc++-v3/include/bits/shared_ptr_atomic.h +++ b/libstdc++-v3/include/bits/shared_ptr_atomic.h @@ -357,7 +357,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Ensure we can use the LSB as the lock bit. static_assert(alignof(remove_pointer_t) > 1); - _Atomic_count() : _M_val(0) { } + constexpr _Atomic_count() noexcept = default; explicit _Atomic_count(__count_type&& __c) noexcept @@ -457,7 +457,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static constexpr uintptr_t _S_lock_bit{1}; }; - typename _Tp::element_type* _M_ptr; + typename _Tp::element_type* _M_ptr = nullptr; _Atomic_count _M_refcount; static typename _Atomic_count::pointer diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc index 725e7ba5031..1f97224bf6a 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc @@ -16,6 +16,9 @@ #include +// Check constexpr constructor. +constinit std::atomic> a; + void test_is_lock_free() { diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/atomic_weak_ptr.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/atomic_weak_ptr.cc index e394e5562b9..b38cea768c8 100644 --- a/libstdc++-v3/testsuite/20_util/weak_ptr/atomic_weak_ptr.cc +++ b/libstdc++-v3/testsuite/20_util/weak_ptr/atomic_weak_ptr.cc @@ -8,6 +8,9 @@ #include #include +// Check constexpr constructor. +constinit std::atomic> a; + void test_is_lock_free() { -- 2.31.1