This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
4294.bitset(const CharT*)
constructor needs to be constrained
Section: 22.9.2.2 [bitset.cons] Status: New Submitter: Jonathan Wakely Opened: 2025-07-12 Last modified: 2025-07-15
Priority: Not Prioritized
View all other issues in [bitset.cons].
View all issues with New status.
Discussion:
This code might be ill-formed, with an error outside the immediate context that users cannot prevent:
#include <bitset> struct NonTrivial { ~NonTrivial() { } }; static_assert( ! std::is_constructible_v<std::bitset<1>, NonTrivial*> );
The problem is that the bitset(const CharT*)
constructor tries to instantiate basic_string_view<NonTrivial>
to find its size_type
, and that instantiation might ill-formed, e.g. if std::basic_string_view
or std::char_traits
has a static assert enforcing the requirement for their character type to be sufficiently char-like. 27.1 [strings.general] defines a char-like type as "any non-array trivially copyable standard-layout (6.9.1 [basic.types.general]) type T
where is_trivially_default_constructible_v<T>
is true
."
Proposed resolution:
This wording is relative to N5008.
Modify 22.9.2.2 [bitset.cons] as indicated:
template<class charT> constexpr explicit bitset( const charT* str, typename basic_string_view<charT>::size_type n = basic_string_view<charT>::npos, charT zero = charT(’0’), charT one = charT(’1’));
-?- Constraints:
is_array_v<charT>
isfalse
,is_trivially_copyable_v<charT>
istrue
,is_standard_layout_v<charT>
istrue
, andis_trivially_default_constructible_v<charT>
istrue
.-8- Effects: As if by:
bitset(n == basic_string_view<charT>::npos ? basic_string_view<charT>(str) : basic_string_view<charT>(str, n), 0, n, zero, one)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4