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-12

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]).

Proposed resolution:

This wording is relative to N5008.

  1. 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> is false.
    • is_trivially_copyable_v<charT> is true.
    • is_standard_layout_v<charT> is true.
    • is_trivially_default_constructible_v<charT> is true.

    -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)