Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P2166R1 Prohibiting basic_string And basic_string_view Construction From nullptr #1995

Merged
merged 14 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions stl/inc/xstring
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,10 @@ public:
#endif // _CONTAINER_DEBUG_LEVEL > 0
}

#if _HAS_CXX23
constexpr basic_string_view(nullptr_t) = delete;
#endif // _HAS_CXX23
sam20908 marked this conversation as resolved.
Show resolved Hide resolved

#ifdef __cpp_lib_concepts
// clang-format off
template <contiguous_iterator _It, sized_sentinel_for<_It> _Se>
Expand Down Expand Up @@ -2534,6 +2538,10 @@ public:
_Proxy._Release();
}

#if _HAS_CXX23
_CONSTEXPR20_CONTAINER basic_string(nullptr_t) = delete;
#endif // _HAS_CXX23
sam20908 marked this conversation as resolved.
Show resolved Hide resolved

_CONSTEXPR20_CONTAINER basic_string(_CRT_GUARDOVERFLOW const size_type _Count, const _Elem _Ch)
: _Mypair(_Zero_then_variadic_args_t{}) {
// construct from _Count * _Ch
Expand Down Expand Up @@ -3100,6 +3108,10 @@ public:
return *this;
}

#if _HAS_CXX23
_CONSTEXPR20_CONTAINER basic_string& operator=(nullptr_t) = delete;
#endif // _HAS_CXX23
sam20908 marked this conversation as resolved.
Show resolved Hide resolved

_CONSTEXPR20_CONTAINER basic_string& operator+=(const basic_string& _Right) {
return append(_Right);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/std/tests/P0220R1_string_view/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,13 @@ static_assert(u8"abc"sv[1] == u8'b');
static_assert(noexcept(u8"abc"sv));
#endif // __cpp_char8_t

// P2166R1 Prohibit std::basic_string and std::basic_string_view construction from nullptr
sam20908 marked this conversation as resolved.
Show resolved Hide resolved
#if _HAS_CXX23
static_assert(!is_constructible_v<string_view, nullptr_t>, "constructing string_view from nullptr_t is prohibited");
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
static_assert(!is_constructible_v<string, nullptr_t>, "constructing string from nullptr_t is prohibited");
static_assert(!is_assignable_v<string, nullptr_t>, "assigning string to nullptr_t is prohibited");
sam20908 marked this conversation as resolved.
Show resolved Hide resolved
#endif
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved

int main() {
test_case_default_constructor();
test_case_ntcts_constructor();
Expand Down