libstdc++: Fix overconstrained std::string constructor [PR103919]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 5 Jan 2022 15:16:33 +0000 (15:16 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 5 Jan 2022 15:31:04 +0000 (15:31 +0000)
commit6aa0859afaf28f4fb13121352225bc5877e02a44
treea601c01e4b0752a19f48161cfd77a92870934e64
parent3633cc54284450433b81f0340483e15df1a49a3c
libstdc++: Fix overconstrained std::string constructor [PR103919]

The C++17 basic_string(const T&, size_t, size_t) constructor is
overconstrained, so it can't be used for a NTBS and a temporary string
gets constructed (potentially allocating memory). There is no
corresponding constructor taking an NTBS, so no need to disambiguate
from it. Accepting an NTBS avoids the temporary (and potential
allocation) and is what the standard requires.

libstdc++-v3/ChangeLog:

PR libstdc++/103919
* include/bits/basic_string.h (basic_string(const T&, size_t, size_t)):
Relax constraints on string_view parameter.
* include/bits/cow_string.h (basic_string(const T&, size_t, size_t)):
Likewise.
* testsuite/21_strings/basic_string/cons/char/103919.cc: New test.
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/include/bits/cow_string.h
libstdc++-v3/testsuite/21_strings/basic_string/cons/char/103919.cc [new file with mode: 0644]