diff --git a/libcxx/include/__string b/libcxx/include/__string --- a/libcxx/include/__string +++ b/libcxx/include/__string @@ -93,11 +93,14 @@ size_t length(const char_type* __s); _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 const char_type* find(const char_type* __s, size_t __n, const char_type& __a); - static char_type* move(char_type* __s1, const char_type* __s2, size_t __n); + static _LIBCPP_CONSTEXPR_AFTER_CXX17 + char_type* move(char_type* __s1, const char_type* __s2, size_t __n); _LIBCPP_INLINE_VISIBILITY - static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); + static _LIBCPP_CONSTEXPR_AFTER_CXX17 + char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); _LIBCPP_INLINE_VISIBILITY - static char_type* assign(char_type* __s, size_t __n, char_type __a); + static _LIBCPP_CONSTEXPR_AFTER_CXX17 + char_type* assign(char_type* __s, size_t __n, char_type __a); static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT {return eq_int_type(__c, eof()) ? ~eof() : __c;} @@ -151,7 +154,7 @@ } template -_CharT* +_LIBCPP_CONSTEXPR_AFTER_CXX17 _CharT* char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n) { char_type* __r = __s1; @@ -171,7 +174,7 @@ } template -inline +inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _CharT* char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n) { @@ -183,7 +186,7 @@ } template -inline +inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _CharT* char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a) { @@ -217,15 +220,41 @@ length(const char_type* __s) _NOEXCEPT {return __builtin_strlen(__s);} static _LIBCPP_CONSTEXPR_AFTER_CXX14 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; - static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT - {return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);} - static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 + char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + { + if (__n == 0) return __s1; + if (!__libcpp_is_constant_evaluated()) { + return (char_type*)memmove(__s1, __s2, __n); + } + if (__s1 < __s2) { + _VSTD::copy(__s2, __s2 + __n, __s1); + } else { + _VSTD::copy_backward(__s2, __s2 + __n, __s1 + __n); + } + return __s1; + } + static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 + char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT { _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); - return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n); + if (__n == 0) return __s1; + if (!__libcpp_is_constant_evaluated()) { + return (char_type*)memcpy(__s1, __s2, __n); + } + _VSTD::copy(__s2, __s2 + __n, __s1); + return __s1; + } + static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 + char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT + { + if (__n == 0) return __s; + if (!__libcpp_is_constant_evaluated()) { + return (char_type*)memset(__s, to_int_type(__a), __n); + } + _VSTD::fill(__s, __s + __n, __a); + return __s; } - static inline char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT - {return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);} static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT {return eq_int_type(__c, eof()) ? ~eof() : __c;} @@ -307,16 +336,41 @@ size_t length(const char_type* __s) _NOEXCEPT; static _LIBCPP_CONSTEXPR_AFTER_CXX14 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; - static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT - {return __n == 0 ? __s1 : (char_type*)wmemmove(__s1, __s2, __n);} - static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 + char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + { + if (__n == 0) return __s1; + if (!__libcpp_is_constant_evaluated()) { + return (char_type*)wmemmove(__s1, __s2, __n); + } + if (__s1 < __s2) { + _VSTD::copy(__s2, __s2 + __n, __s1); + } else { + _VSTD::copy_backward(__s2, __s2 + __n, __s1 + __n); + } + return __s1; + } + static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 + char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT { _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); - return __n == 0 ? __s1 : (char_type*)wmemcpy(__s1, __s2, __n); + if (__n == 0) return __s1; + if (!__libcpp_is_constant_evaluated()) { + return (char_type*)wmemcpy(__s1, __s2, __n); + } + _VSTD::copy(__s2, __s2 + __n, __s1); + return __s1; + } + static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 + char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT + { + if (__n == 0) return __s; + if (!__libcpp_is_constant_evaluated()) { + return (char_type*)wmemset(__s, __a, __n); + } + _VSTD::fill(__s, __s + __n, __a); + return __s; } - static inline char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT - {return __n == 0 ? __s : (char_type*)wmemset(__s, __a, __n);} - static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT {return eq_int_type(__c, eof()) ? ~eof() : __c;} static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT @@ -424,21 +478,47 @@ static constexpr size_t length(const char_type* __s) _NOEXCEPT; - + _LIBCPP_INLINE_VISIBILITY static constexpr const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; - - static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT - {return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);} - - static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + + static constexpr + char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + { + if (__n == 0) return __s1; + if (!__libcpp_is_constant_evaluated()) { + return (char_type*)memmove(__s1, __s2, __n); + } + if (__s1 < __s2) { + _VSTD::copy(__s2, __s2 + __n, __s1); + } else { + _VSTD::copy_backward(__s2, __s2 + __n, __s1 + __n); + } + return __s1; + } + + static constexpr + char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT { _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); - return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n); - } - - static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT - {return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);} + if (__n == 0) return __s1; + if (!__libcpp_is_constant_evaluated()) { + return (char_type*)memcpy(__s1, __s2, __n); + } + _VSTD::copy(__s2, __s2 + __n, __s1); + return __s1; + } + + static constexpr + char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT + { + if (__n == 0) return __s; + if (!__libcpp_is_constant_evaluated()) { + return (char_type*)memset(__s, to_int_type(__a), __n); + } + _VSTD::fill(__s, __s + __n, __a); + return __s; + } static inline constexpr int_type not_eof(int_type __c) noexcept {return eq_int_type(__c, eof()) ? ~eof() : __c;} @@ -521,11 +601,11 @@ size_t length(const char_type* __s) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT; static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT @@ -577,10 +657,11 @@ return 0; } -inline +inline _LIBCPP_CONSTEXPR_AFTER_CXX17 char16_t* char_traits::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT { + if (__n == 0) return __s1; char_type* __r = __s1; if (__s1 < __s2) { @@ -597,21 +678,23 @@ return __r; } -inline +inline _LIBCPP_CONSTEXPR_AFTER_CXX17 char16_t* char_traits::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT { _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + if (__n == 0) return __s1; char_type* __r = __s1; for (; __n; --__n, ++__s1, ++__s2) assign(*__s1, *__s2); return __r; } -inline +inline _LIBCPP_CONSTEXPR_AFTER_CXX17 char16_t* char_traits::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT { + if (__n == 0) return __s; char_type* __r = __s; for (; __n; --__n, ++__s) assign(*__s, __a); @@ -640,11 +723,11 @@ size_t length(const char_type* __s) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT; static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT @@ -696,10 +779,11 @@ return 0; } -inline +inline _LIBCPP_CONSTEXPR_AFTER_CXX17 char32_t* char_traits::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT { + if (__n == 0) return __s1; char_type* __r = __s1; if (__s1 < __s2) { @@ -716,21 +800,23 @@ return __r; } -inline +inline _LIBCPP_CONSTEXPR_AFTER_CXX17 char32_t* char_traits::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT { _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + if (__n == 0) return __s1; char_type* __r = __s1; for (; __n; --__n, ++__s1, ++__s2) assign(*__s1, *__s2); return __r; } -inline +inline _LIBCPP_CONSTEXPR_AFTER_CXX17 char32_t* char_traits::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT { + if (__n == 0) return __s; char_type* __r = __s; for (; __n; --__n, ++__s) assign(*__s, __a); diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/assign3.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/assign3.pass.cpp --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/assign3.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/assign3.pass.cpp @@ -17,7 +17,7 @@ #include "test_macros.h" -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool test() { char s2[3] = {0}; assert(std::char_traits::assign(s2, 3, char(5)) == s2); @@ -26,5 +26,16 @@ assert(s2[2] == char(5)); assert(std::char_traits::assign(NULL, 0, char(5)) == NULL); + return true; +} + +int main(int, char**) +{ + test(); + +#if TEST_STD_VER > 17 + static_assert(test(), ""); +#endif + return 0; } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/copy.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/copy.pass.cpp --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/copy.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/copy.pass.cpp @@ -17,7 +17,7 @@ #include "test_macros.h" -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool test() { char s1[] = {1, 2, 3}; char s2[3] = {0}; @@ -28,5 +28,16 @@ assert(std::char_traits::copy(NULL, s1, 0) == NULL); assert(std::char_traits::copy(s1, NULL, 0) == s1); + return true; +} + +int main(int, char**) +{ + test(); + +#if TEST_STD_VER > 17 + static_assert(test(), ""); +#endif + return 0; } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/move.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/move.pass.cpp --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/move.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/move.pass.cpp @@ -17,7 +17,7 @@ #include "test_macros.h" -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool test() { char s1[] = {1, 2, 3}; assert(std::char_traits::move(s1, s1+1, 2) == s1); @@ -32,5 +32,16 @@ assert(std::char_traits::move(NULL, s1, 0) == NULL); assert(std::char_traits::move(s1, NULL, 0) == s1); + return true; +} + +int main(int, char**) +{ + test(); + +#if TEST_STD_VER > 17 + static_assert(test(), ""); +#endif + return 0; } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign3.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign3.pass.cpp --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign3.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign3.pass.cpp @@ -17,7 +17,7 @@ #include "test_macros.h" -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool test() { #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS char16_t s2[3] = {0}; @@ -28,5 +28,16 @@ assert(std::char_traits::assign(NULL, 0, char16_t(5)) == NULL); #endif // _LIBCPP_HAS_NO_UNICODE_CHARS + return true; +} + +int main(int, char**) +{ + test(); + +#if TEST_STD_VER > 17 + static_assert(test(), ""); +#endif + return 0; } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/copy.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/copy.pass.cpp --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/copy.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/copy.pass.cpp @@ -17,7 +17,7 @@ #include "test_macros.h" -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool test() { #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS char16_t s1[] = {1, 2, 3}; @@ -30,5 +30,16 @@ assert(std::char_traits::copy(s1, NULL, 0) == s1); #endif // _LIBCPP_HAS_NO_UNICODE_CHARS + return true; +} + +int main(int, char**) +{ + test(); + +#if TEST_STD_VER > 17 + static_assert(test(), ""); +#endif + return 0; } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/move.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/move.pass.cpp --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/move.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/move.pass.cpp @@ -17,7 +17,7 @@ #include "test_macros.h" -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool test() { #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS char16_t s1[] = {1, 2, 3}; @@ -34,5 +34,16 @@ assert(std::char_traits::move(s1, NULL, 0) == s1); #endif // _LIBCPP_HAS_NO_UNICODE_CHARS + return true; +} + +int main(int, char**) +{ + test(); + +#if TEST_STD_VER > 17 + static_assert(test(), ""); +#endif + return 0; } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign3.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign3.pass.cpp --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign3.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign3.pass.cpp @@ -17,7 +17,7 @@ #include "test_macros.h" -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool test() { #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS char32_t s2[3] = {0}; @@ -28,5 +28,16 @@ assert(std::char_traits::assign(NULL, 0, char32_t(5)) == NULL); #endif // _LIBCPP_HAS_NO_UNICODE_CHARS + return true; +} + +int main(int, char**) +{ + test(); + +#if TEST_STD_VER > 17 + static_assert(test(), ""); +#endif + return 0; } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/copy.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/copy.pass.cpp --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/copy.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/copy.pass.cpp @@ -17,7 +17,7 @@ #include "test_macros.h" -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool test() { #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS char32_t s1[] = {1, 2, 3}; @@ -30,5 +30,16 @@ assert(std::char_traits::copy(s1, NULL, 0) == s1); #endif // _LIBCPP_HAS_NO_UNICODE_CHARS + return true; +} + +int main(int, char**) +{ + test(); + +#if TEST_STD_VER > 17 + static_assert(test(), ""); +#endif + return 0; } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/move.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/move.pass.cpp --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/move.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/move.pass.cpp @@ -17,7 +17,7 @@ #include "test_macros.h" -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool test() { #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS char32_t s1[] = {1, 2, 3}; @@ -34,5 +34,16 @@ assert(std::char_traits::move(s1, NULL, 0) == s1); #endif // _LIBCPP_HAS_NO_UNICODE_CHARS + return true; +} + +int main(int, char**) +{ + test(); + +#if TEST_STD_VER > 17 + static_assert(test(), ""); +#endif + return 0; } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/assign3.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/assign3.pass.cpp --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/assign3.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/assign3.pass.cpp @@ -18,7 +18,7 @@ #include "test_macros.h" -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool test() { #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L char8_t s2[3] = {0}; @@ -29,5 +29,16 @@ assert(std::char_traits::assign(NULL, 0, char8_t(5)) == NULL); #endif + return true; +} + +int main(int, char**) +{ + test(); + +#if TEST_STD_VER > 17 + static_assert(test(), ""); +#endif + return 0; } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/copy.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/copy.pass.cpp --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/copy.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/copy.pass.cpp @@ -18,7 +18,7 @@ #include "test_macros.h" -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool test() { #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L char8_t s1[] = {1, 2, 3}; @@ -31,5 +31,16 @@ assert(std::char_traits::copy(s1, NULL, 0) == s1); #endif + return true; +} + +int main(int, char**) +{ + test(); + +#if TEST_STD_VER > 17 + static_assert(test(), ""); +#endif + return 0; } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/move.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/move.pass.cpp --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/move.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/move.pass.cpp @@ -18,7 +18,7 @@ #include "test_macros.h" -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool test() { #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L char8_t s1[] = {1, 2, 3}; @@ -35,5 +35,16 @@ assert(std::char_traits::move(s1, NULL, 0) == s1); #endif + return true; +} + +int main(int, char**) +{ + test(); + +#if TEST_STD_VER > 17 + static_assert(test(), ""); +#endif + return 0; } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/assign3.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/assign3.pass.cpp --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/assign3.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/assign3.pass.cpp @@ -17,7 +17,7 @@ #include "test_macros.h" -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool test() { wchar_t s2[3] = {0}; assert(std::char_traits::assign(s2, 3, wchar_t(5)) == s2); @@ -25,6 +25,16 @@ assert(s2[1] == wchar_t(5)); assert(s2[2] == wchar_t(5)); assert(std::char_traits::assign(NULL, 0, wchar_t(5)) == NULL); + return true; +} + +int main(int, char**) +{ + test(); + +#if TEST_STD_VER > 17 + static_assert(test(), ""); +#endif return 0; } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/copy.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/copy.pass.cpp --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/copy.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/copy.pass.cpp @@ -17,7 +17,7 @@ #include "test_macros.h" -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool test() { wchar_t s1[] = {1, 2, 3}; wchar_t s2[3] = {0}; @@ -27,6 +27,16 @@ assert(s2[2] == wchar_t(3)); assert(std::char_traits::copy(NULL, s1, 0) == NULL); assert(std::char_traits::copy(s1, NULL, 0) == s1); + return true; +} + +int main(int, char**) +{ + test(); + +#if TEST_STD_VER > 17 + static_assert(test(), ""); +#endif return 0; } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/move.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/move.pass.cpp --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/move.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/move.pass.cpp @@ -17,7 +17,7 @@ #include "test_macros.h" -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool test() { wchar_t s1[] = {1, 2, 3}; assert(std::char_traits::move(s1, s1+1, 2) == s1); @@ -31,6 +31,16 @@ assert(s1[2] == wchar_t(3)); assert(std::char_traits::move(NULL, s1, 0) == NULL); assert(std::char_traits::move(s1, NULL, 0) == s1); + return true; +} + +int main(int, char**) +{ + test(); + +#if TEST_STD_VER > 17 + static_assert(test(), ""); +#endif return 0; } diff --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h --- a/libcxx/test/support/test_macros.h +++ b/libcxx/test/support/test_macros.h @@ -125,6 +125,11 @@ # else # define TEST_THROW_SPEC(...) throw(__VA_ARGS__) # endif +# if TEST_STD_VER > 17 +# define TEST_CONSTEXPR_CXX20 constexpr +# else +# define TEST_CONSTEXPR_CXX20 +# endif #else #if defined(TEST_COMPILER_CLANG) # define TEST_ALIGNOF(...) _Alignof(__VA_ARGS__)