]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Check feature test macro for std::string_view in <string>
authorJonathan Wakely <jwakely@redhat.com>
Thu, 3 Apr 2025 12:59:14 +0000 (13:59 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 4 Apr 2025 09:29:57 +0000 (10:29 +0100)
commitaffdef57a45a443ead24f6afb7027a2683028031
treedf959199535a9f9b51cee1c5f0e8da9508d8336e
parent4b884f3d6335539447d32c6462cc4ef52e30e273
libstdc++: Check feature test macro for std::string_view in <string>

We can use the __glibcxx_string_view macro to guard the uses of
std::string_view in <string>, instead of just checking the value of
__cplusplus. It makes no practical difference because
__glibcxx_string_view is defined for C++17 and up, but it makes it clear
to readers that the lines guarded by that macro are features that depend
on string_view.

We could be more precise and check __glibcxx_string_view >= 201606L
which is the value for the P0254R2 paper that integrated
std::string_view with std::string, but I think just checking for the
macro being defined is clear enough.

We can also check __glibcxx_variant for the _Never_valueless_alt partial
specialization.

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h: Check __glibcxx_string_view and
__glibcxx_variant instead of __cplusplus >= 2017L.
* include/bits/cow_string.h: Likewise.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/include/bits/cow_string.h