From patchwork Fri Aug 23 12:18:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1976017 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=bKpFekFz; 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 4Wqzf52cnSz1yXY for ; Fri, 23 Aug 2024 22:19:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 20F3738708FC for ; Fri, 23 Aug 2024 12:19:39 +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.129.124]) by sourceware.org (Postfix) with ESMTP id 2B81F3861037 for ; Fri, 23 Aug 2024 12:19:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B81F3861037 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 2B81F3861037 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724415555; cv=none; b=vQMDZytkjOzYhUfeiehfyiGd4BKsQiJVru7N18btgrPz9J46Xxyy4vQF3iZe6/MXIxONgo7EyDwG7jN0Nd4grO2aXxm1uFP4K5QXNcaET+5ayGsQ7R11iM9Yk0dtEgcuzP+FrUSZUWKa+hw6bwW/uBLY0ABOfb6HgSz/TUQVdOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724415555; c=relaxed/simple; bh=U/PDqx/Lq1LfCGe6tdBQneeqCRG8kXUiXecCR4orJoc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=eiFVJSmcz61qwsPacUoaDKuPjH0LYtB8GQOJdvdW2I2P7l9NjjyLMliaS/civ9EuaQ/21tTlrOqBT1JcLk3wD32V5nOhmGLxZk1jatq2eyjNP6kWVlKiCcq62h90NhFsILBj9EXDc55Sjrpc0lfppQb8UV48rDPQuOcZPWNG9yk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724415552; 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=kEXG6XonAUg0ar3HnBZdd/PYoLsyyTkCuV/jiYg8Vj4=; b=bKpFekFzj513EVv9MPXwAzB4izfIxtqnsC0b3C6AU38JVvNUtb0gI7qZOwU9B45k31j+wW C4ZBV7nltCvAzIm3xcCgUNEZdaEec1EaxagBxieBcacqGrDFsB8gxRF9R4s3sTOqgBE5Qn dmo6OXG9tFz22eQtfM0rpKw5qxHVbK8= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-127-PweSVR19NjqVPznEaFOOHg-1; Fri, 23 Aug 2024 08:19:10 -0400 X-MC-Unique: PweSVR19NjqVPznEaFOOHg-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2DDE7195608A; Fri, 23 Aug 2024 12:19:09 +0000 (UTC) Received: from localhost (unknown [10.42.28.41]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 615381954B39; Fri, 23 Aug 2024 12:19:07 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Make std::vector::reference constructor private [PR115098] Date: Fri, 23 Aug 2024 13:18:46 +0100 Message-ID: <20240823121906.959071-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.4 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_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, URI_HEX 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-linux. Pushed to trunk. -- >8 -- The standard says this constructor should be private. LWG 4141 proposes to remove it entirely. We still need it, but it doesn't need to be public. For std::bitset the default constructor is already private (and never even defined) but there's a non-standard constructor that's public, but doesn't need to be. libstdc++-v3/ChangeLog: PR libstdc++/115098 * include/bits/stl_bvector.h (_Bit_reference): Make default constructor private. Declare vector and bit iterators as friends. * include/std/bitset (bitset::reference): Make constructor and data members private. * testsuite/20_util/bitset/115098.cc: New test. * testsuite/23_containers/vector/bool/115098.cc: New test. --- libstdc++-v3/include/bits/stl_bvector.h | 12 +++++++++--- libstdc++-v3/include/std/bitset | 5 +---- libstdc++-v3/testsuite/20_util/bitset/115098.cc | 11 +++++++++++ .../testsuite/23_containers/vector/bool/115098.cc | 8 ++++++++ 4 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/bitset/115098.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/bool/115098.cc diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index c45b7ff3320..42261ac5915 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -81,6 +81,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER struct _Bit_reference { + private: + template friend class vector; + friend struct _Bit_iterator; + friend struct _Bit_const_iterator; + + _GLIBCXX20_CONSTEXPR + _Bit_reference() _GLIBCXX_NOEXCEPT : _M_p(0), _M_mask(0) { } + _Bit_type * _M_p; _Bit_type _M_mask; @@ -88,9 +96,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _Bit_reference(_Bit_type * __x, _Bit_type __y) : _M_p(__x), _M_mask(__y) { } - _GLIBCXX20_CONSTEXPR - _Bit_reference() _GLIBCXX_NOEXCEPT : _M_p(0), _M_mask(0) { } - + public: #if __cplusplus >= 201103L _Bit_reference(const _Bit_reference&) = default; #endif diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset index e5d677ff059..2e82a0e289d 100644 --- a/libstdc++-v3/include/std/bitset +++ b/libstdc++-v3/include/std/bitset @@ -870,10 +870,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _WordT* _M_wp; size_t _M_bpos; - // left undefined - reference(); - - public: _GLIBCXX23_CONSTEXPR reference(bitset& __b, size_t __pos) _GLIBCXX_NOEXCEPT { @@ -881,6 +877,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_bpos = _Base::_S_whichbit(__pos); } + public: #if __cplusplus >= 201103L reference(const reference&) = default; #endif diff --git a/libstdc++-v3/testsuite/20_util/bitset/115098.cc b/libstdc++-v3/testsuite/20_util/bitset/115098.cc new file mode 100644 index 00000000000..52d6a0ec378 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/115098.cc @@ -0,0 +1,11 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace std; + +static_assert( ! is_default_constructible::reference>::value, + "std::bitset::reference is not default constructible"); + +static_assert( ! is_constructible::reference, bitset<10>&, size_t>::value, + "std::bitset::reference is not default constructible"); diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/115098.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/115098.cc new file mode 100644 index 00000000000..3df8b801795 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/115098.cc @@ -0,0 +1,8 @@ +// { dg-do compile { target c++11 } } + +#include + +static_assert( + !std::is_default_constructible::reference>::value, + "std::vector::reference is not default constructible" + );