diff --git a/stl/inc/xstring b/stl/inc/xstring index 28593f1cca4..2edb3cf74d2 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -1191,6 +1191,10 @@ struct pointer_traits<_String_view_iterator<_Traits>> { }; #endif // _HAS_CXX20 +#pragma warning(push) +// Invalid annotation: 'NullTerminated' property may only be used on buffers whose elements are of integral or pointer +// type +#pragma warning(disable : 6510) template class basic_string_view { // wrapper for any kind of contiguous character buffer @@ -1656,6 +1660,8 @@ private: size_type _Mysize; }; +#pragma warning(pop) + #ifdef __cpp_lib_concepts template _Sent> basic_string_view(_Iter, _Sent) -> basic_string_view>; diff --git a/tests/std/tests/P0220R1_string_view/test.cpp b/tests/std/tests/P0220R1_string_view/test.cpp index b8b506432d5..120bba80022 100644 --- a/tests/std/tests/P0220R1_string_view/test.cpp +++ b/tests/std/tests/P0220R1_string_view/test.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -1251,6 +1252,38 @@ static_assert(!is_constructible_v, "constructing string from static_assert(!is_assignable_v, "assigning nullptr_t to string is prohibited"); #endif // _HAS_CXX23 +// Also test that no C6510 warning +struct char_wrapper { + char c; +}; + +template <> +struct std::char_traits { + using char_type = char_wrapper; + + static bool eq(char_wrapper lhs, char_wrapper rhs) { + return lhs.c == rhs.c; + } + + static size_t length(const char_wrapper* a) { + static_assert(sizeof(char_wrapper) == 1, "strlen requires this"); + return strlen(reinterpret_cast(a)); + } + + static int compare(const char_wrapper* lhs, const char_wrapper* rhs, size_t count) { + return char_traits::compare( + reinterpret_cast(lhs), reinterpret_cast(rhs), count); + } +}; + +using WrappedSV = basic_string_view>; + +void test_C6510_warning() { // compile-only + char_wrapper a[] = {{'a'}, {'b'}, {'c'}, {'\0'}}; + WrappedSV sv(a); + (void) sv; +} + int main() { test_case_default_constructor(); test_case_ntcts_constructor();