libstdc++: Make std::vector<bool>::reference constructor private [PR115098]
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.
This commit is contained in:
parent
f9f599a44e
commit
b25b101bc3
4 changed files with 29 additions and 7 deletions
|
@ -81,6 +81,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
|
|||
|
||||
struct _Bit_reference
|
||||
{
|
||||
private:
|
||||
template<typename, typename> 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
|
||||
|
|
|
@ -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
|
||||
|
|
11
libstdc++-v3/testsuite/20_util/bitset/115098.cc
Normal file
11
libstdc++-v3/testsuite/20_util/bitset/115098.cc
Normal file
|
@ -0,0 +1,11 @@
|
|||
// { dg-do compile { target c++11 } }
|
||||
|
||||
#include <bitset>
|
||||
|
||||
using namespace std;
|
||||
|
||||
static_assert( ! is_default_constructible<bitset<10>::reference>::value,
|
||||
"std::bitset<N>::reference is not default constructible");
|
||||
|
||||
static_assert( ! is_constructible<bitset<10>::reference, bitset<10>&, size_t>::value,
|
||||
"std::bitset<N>::reference is not default constructible");
|
|
@ -0,0 +1,8 @@
|
|||
// { dg-do compile { target c++11 } }
|
||||
|
||||
#include <vector>
|
||||
|
||||
static_assert(
|
||||
!std::is_default_constructible<std::vector<bool>::reference>::value,
|
||||
"std::vector<bool>::reference is not default constructible"
|
||||
);
|
Loading…
Add table
Reference in a new issue