зеркало из https://github.com/microsoft/STL.git
`<string_view>`: suppress warning about annotation 'NullTerminated' (#3032)
Co-authored-by: Casey Carter <Casey@Carter.net>
This commit is contained in:
Родитель
ae0c274dd3
Коммит
ed0e3e5ad9
|
@ -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 _Elem, class _Traits>
|
||||
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 <contiguous_iterator _Iter, sized_sentinel_for<_Iter> _Sent>
|
||||
basic_string_view(_Iter, _Sent) -> basic_string_view<iter_value_t<_Iter>>;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <deque>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
@ -1255,6 +1256,38 @@ static_assert(!is_constructible_v<string, nullptr_t>, "constructing string from
|
|||
static_assert(!is_assignable_v<string&, nullptr_t>, "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<char_wrapper> {
|
||||
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<const char*>(a));
|
||||
}
|
||||
|
||||
static int compare(const char_wrapper* lhs, const char_wrapper* rhs, size_t count) {
|
||||
return char_traits<char>::compare(
|
||||
reinterpret_cast<const char*>(lhs), reinterpret_cast<const char*>(rhs), count);
|
||||
}
|
||||
};
|
||||
|
||||
using WrappedSV = basic_string_view<char_wrapper, char_traits<char_wrapper>>;
|
||||
|
||||
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();
|
||||
|
|
Загрузка…
Ссылка в новой задаче