This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Dup status.

3311. basic_string::operator=(charT c) should be constrained

Section: 23.4.3.3 [string.cons] Status: Dup Submitter: Russia Opened: 2019-11-04 Last modified: 2019-11-16

Priority: Not Prioritized

View all other issues in [string.cons].

View all issues with Dup status.

Discussion:

Addresses RU 013

Because of the implicit conversion of arithmetic types it is error prone to use the basic_string::operator=(charT c):

double d = 3.14;
std::string s;
s = d; // Compiles

Make sure that the program is ill-formed if an implicit conversion from arithmetic type happens while assigning to std::basic_string. Or at least make sure that the program is ill-formed if an implicit conversion from floating point type happens while assigning to std::basic_string.

[2019-11 Status to Duplicate during Tuesday morning issue processing in Belfast.]

Duplicate of 2372.

Proposed resolution:

This wording is relative to N4835.

  1. Modify 23.4.3 [basic.string] p3, class template basic_string synopsis, as indicated:

    template<class T>
    constexpr basic_string& operator=(charT c);
    
  2. Modify 23.4.3.3 [string.cons] as indicated:

    template<class T>
    constexpr basic_string& operator=(charT c);
    

    -?- Constraints: is_same_v<T, charT> is true.

    -30- Effects: Equivalent to:

    return *this = basic_string_view<charT, traits>(addressof(c), 1);