diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index a91ba5114b1..fc6a303a957 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -728,10 +728,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 else _M_construct(__str.begin(), __str.end(), std::forward_iterator_tag()); } +#endif // C++11 +#if __cplusplus >= 202100L basic_string(nullptr_t) = delete; basic_string& operator=(nullptr_t) = delete; -#endif // C++11 +#endif // C++23 /** * @brief Construct string as copy of a range. diff --git a/libstdc++-v3/include/bits/cow_string.h b/libstdc++-v3/include/bits/cow_string.h index 84aab2f33c6..a49a5b04f2f 100644 --- a/libstdc++-v3/include/bits/cow_string.h +++ b/libstdc++-v3/include/bits/cow_string.h @@ -665,10 +665,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION else _M_dataplus._M_p = _S_construct(__str.begin(), __str.end(), __a); } +#endif // C++11 +#if __cplusplus >= 202100L basic_string(nullptr_t) = delete; basic_string& operator=(nullptr_t) = delete; -#endif // C++11 +#endif // C++23 /** * @brief Construct string as copy of a range. diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view index 99080e9eccd..bccf4d1847f 100644 --- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -167,10 +167,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION noexcept(noexcept(ranges::size(__r)) && noexcept(ranges::data(__r))) : _M_len(ranges::size(__r)), _M_str(ranges::data(__r)) { } + + basic_string_view(nullptr_t) = delete; #endif // C++23 #endif // C++20 - basic_string_view(nullptr_t) = delete; constexpr basic_string_view& operator=(const basic_string_view&) noexcept = default; diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/nullptr.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/nullptr.cc index fdb24aeeb89..a69fa614ba3 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/nullptr.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/nullptr.cc @@ -1,4 +1,28 @@ // { dg-do compile { target c++11 } } #include -std::string s = nullptr; // { dg-error "deleted" "P2166R1" } +std::string s = nullptr; // { dg-error "deleted" "P2166R1" { target c++23 } } + +struct S +{ + operator const char*() const { return ""; } + operator std::nullptr_t() const { return {}; } +}; + +std::string s2{ S{} }; // { dg-error "deleted" "PR 104099" { target c++23 } } + +#if __cpp_concepts +struct J +{ + // In C++20 this selects basic_string(const char*), + // in C++23 it's ambiguous due to basic_string(nullptr_t). + template + requires (!std::is_same_v, T>) + && (!std::is_same_v) + && (!std::is_same_v) + && (!std::is_same_v) + operator T() const { return {}; } +}; + +std::string s3{ J{} }; // { dg-error "ambiguous" "PR 104099" { target c++23 } } +#endif diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/nonnull.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/nonnull.cc index 00bb8e414b8..2e43788e4f5 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/nonnull.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/nonnull.cc @@ -25,5 +25,6 @@ test01() { std::string_view s((const char*)nullptr); // { dg-warning "\\\[-Wnonnull" } std::string_view t((char*)nullptr); // { dg-warning "\\\[-Wnonnull" } - std::string_view u(nullptr); // { dg-error "deleted" } + std::string_view u(nullptr); // { dg-warning "\\\[-Wnonnull" "" { target c++20_down } } +// { dg-error "deleted" "P2166R1" { target c++23 } 0 } } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/wchar_t/nonnull.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/wchar_t/nonnull.cc index 685d48c3fd7..a146d383324 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/wchar_t/nonnull.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/wchar_t/nonnull.cc @@ -25,5 +25,6 @@ test01() { std::wstring_view s((const wchar_t*)nullptr); // { dg-warning "\\\[-Wnonnull" } std::wstring_view t((wchar_t*)nullptr); // { dg-warning "\\\[-Wnonnull" } - std::wstring_view u(nullptr); // { dg-error "deleted" } + std::wstring_view u(nullptr); // { dg-warning "\\\[-Wnonnull" "" { target c++20_down } } +// { dg-error "deleted" "P2166R1" { target c++23 } 0 } }