This patch attempts to solve an issue in basic_string after adding
string_view to several functions that came in during incomplete patch
of LWG 2758/LWG 2946, in short: Functions that take a string_view
parameter value are now replaced by constrained templates taking const
T& that is convertible to string_view. The patch also attempts to
complete the LWG 2946 P/R. With the absence of the
std::is_nothrow_convertible traits, the P/R also restores some of the
lost noexcept specifications of const functions (find, compare, etc)
by conditional noexcept simply comparing whether T is the same type as
string_view.

During that fix two related, minor problems where found and also fixed:

a) Member

int compare(basic_string_view<charT, traits> sv) const;

should be noexcept according the spec, but this function wasn't at
all. Since the changes for LWG 2946 required me to touch the noexcept
specifier anyway I replaced it by the conditional noexcept mentioned
above. I do not know what the general policy for "narrow contract"
functions is in libstdc++ code, I therefore didn't touch the also
missing (but optional) noexcept for

int compare(size_type pos1, size_type n1,basic_string_view<charT,
traits> sv) const;
template<class T>
int compare(size_type pos1, size_type n1, const T& t, size_type pos2,
size_type n2 = npos) const;

If wanted, I can apply the same conditional noexcept here as well.

b) Two constructors using the const T& -> string_view conversion did
this via explicit conversion instead of implicit conversion. This
difference can be observed by user-code and in certain cases either a
well-formed program can become ill-formed or may perform different
runtime behaviour (Overloaded conversion operators, one explicit, the
other implicit).

This patch is *untested*, because I cannot make the tests run on my
Windows system.

Thanks,

- Daniel

Attachment: ChangeLog_79162.patch
Description: Binary data

Attachment: 79162.patch
Description: Binary data

Reply via email to