diff --git a/libcxx/include/__string b/libcxx/include/__string index 0b851b9f9e2b..8152660ac19c 100644 --- a/libcxx/include/__string +++ b/libcxx/include/__string @@ -26,13 +26,14 @@ struct char_traits typedef streampos pos_type; typedef mbstate_t state_type; - static void assign(char_type& c1, const char_type& c2) noexcept; + static constexpr void assign(char_type& c1, const char_type& c2) noexcept; static constexpr bool eq(char_type c1, char_type c2) noexcept; static constexpr bool lt(char_type c1, char_type c2) noexcept; - static int compare(const char_type* s1, const char_type* s2, size_t n); - static size_t length(const char_type* s); - static const char_type* find(const char_type* s, size_t n, const char_type& a); + static constexpr int compare(const char_type* s1, const char_type* s2, size_t n); + static constexpr size_t length(const char_type* s); + static constexpr 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 char_type* copy(char_type* s1, const char_type* s2, size_t n); static char_type* assign(char_type* s, size_t n, char_type a); @@ -77,18 +78,19 @@ struct _LIBCPP_TEMPLATE_VIS char_traits typedef streampos pos_type; typedef mbstate_t state_type; - static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT - {__c1 = __c2;} + static inline void _LIBCPP_CONSTEXPR_AFTER_CXX14 + assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 == __c2;} static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 < __c2;} - static int compare(const char_type* __s1, const char_type* __s2, size_t __n); - _LIBCPP_INLINE_VISIBILITY - static size_t length(const char_type* __s); - _LIBCPP_INLINE_VISIBILITY - static const char_type* find(const char_type* __s, size_t __n, const char_type& __a); + static _LIBCPP_CONSTEXPR_AFTER_CXX14 + int compare(const char_type* __s1, const char_type* __s2, size_t __n); + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + 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); _LIBCPP_INLINE_VISIBILITY static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); @@ -108,7 +110,7 @@ struct _LIBCPP_TEMPLATE_VIS char_traits }; template -int +_LIBCPP_CONSTEXPR_AFTER_CXX14 int char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n) { for (; __n; --__n, ++__s1, ++__s2) @@ -123,7 +125,7 @@ char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_ template inline -size_t +_LIBCPP_CONSTEXPR_AFTER_CXX14 size_t char_traits<_CharT>::length(const char_type* __s) { size_t __len = 0; @@ -134,7 +136,7 @@ char_traits<_CharT>::length(const char_type* __s) template inline -const _CharT* +_LIBCPP_CONSTEXPR_AFTER_CXX14 const _CharT* char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a) { for (; __n; --__n) @@ -200,18 +202,20 @@ struct _LIBCPP_TEMPLATE_VIS char_traits typedef streampos pos_type; typedef mbstate_t state_type; - static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT - {__c1 = __c2;} + static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 + void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 == __c2;} static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT {return (unsigned char)__c1 < (unsigned char)__c2;} - static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT - {return __n == 0 ? 0 : memcmp(__s1, __s2, __n);} - static inline size_t length(const char_type* __s) _NOEXCEPT {return strlen(__s);} - static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT - {return __n == 0 ? NULL : (const char_type*) memchr(__s, to_int_type(__a), __n);} + static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 + int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + {return __n == 0 ? 0 : __builtin_memcmp(__s1, __s2, __n);} + static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14 + 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 @@ -234,6 +238,26 @@ struct _LIBCPP_TEMPLATE_VIS char_traits {return int_type(EOF);} }; +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +const char* +char_traits::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT +{ + if (__n == 0) + return NULL; +#if _LIBCPP_STD_VER <= 14 + return (const char_type*) memchr(__s, to_int_type(__a), __n); +#else + for (; __n; --__n) + { + if (eq(*__s, __a)) + return __s; + ++__s; + } + return NULL; +#endif +} + + // char_traits template <> @@ -245,19 +269,19 @@ struct _LIBCPP_TEMPLATE_VIS char_traits typedef streampos pos_type; typedef mbstate_t state_type; - static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT - {__c1 = __c2;} + static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 + void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 == __c2;} static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 < __c2;} - static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT - {return __n == 0 ? 0 : wmemcmp(__s1, __s2, __n);} - static inline size_t length(const char_type* __s) _NOEXCEPT - {return wcslen(__s);} - static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT - {return __n == 0 ? NULL : (const char_type*)wmemchr(__s, __a, __n);} + static _LIBCPP_CONSTEXPR_AFTER_CXX14 + int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + static _LIBCPP_CONSTEXPR_AFTER_CXX14 + 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 @@ -280,6 +304,66 @@ struct _LIBCPP_TEMPLATE_VIS char_traits {return int_type(WEOF);} }; +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +int +char_traits::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + if (__n == 0) + return 0; +#if __has_builtin(__builtin_wmemcmp) + return __builtin_wmemcmp(__s1, __s2, __n); +#elif _LIBCPP_STD_VER <= 14 + return wmemcmp(__s1, __s2, __n); +#else + for (; __n; --__n, ++__s1, ++__s2) + { + if (lt(*__s1, *__s2)) + return -1; + if (lt(*__s2, *__s1)) + return 1; + } + return 0; +#endif +} + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +size_t +char_traits::length(const char_type* __s) _NOEXCEPT +{ +#if __has_builtin(__builtin_wcslen) + return __builtin_wcslen(__s); +#elif _LIBCPP_STD_VER <= 14 + return wcslen(__s); +#else + size_t __len = 0; + for (; !eq(*__s, char_type(0)); ++__s) + ++__len; + return __len; +#endif +} + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +const wchar_t* +char_traits::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT +{ + if (__n == 0) + return NULL; +#if __has_builtin(__builtin_wmemchr) + return __builtin_wmemchr(__s, __a, __n); +#elif _LIBCPP_STD_VER <= 14 + return wmemchr(__s, __a, __n); +#else + for (; __n; --__n) + { + if (eq(*__s, __a)) + return __s; + ++__s; + } + return NULL; +#endif +} + + #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS template <> @@ -291,19 +375,19 @@ struct _LIBCPP_TEMPLATE_VIS char_traits typedef u16streampos pos_type; typedef mbstate_t state_type; - static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT - {__c1 = __c2;} + static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 + void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 == __c2;} static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 < __c2;} - _LIBCPP_INLINE_VISIBILITY - static int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY - static size_t length(const char_type* __s) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY - static const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + 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 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY @@ -323,7 +407,7 @@ struct _LIBCPP_TEMPLATE_VIS char_traits {return int_type(0xFFFF);} }; -inline +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 int char_traits::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT { @@ -337,7 +421,7 @@ char_traits::compare(const char_type* __s1, const char_type* __s2, siz return 0; } -inline +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 size_t char_traits::length(const char_type* __s) _NOEXCEPT { @@ -347,7 +431,7 @@ char_traits::length(const char_type* __s) _NOEXCEPT return __len; } -inline +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 const char16_t* char_traits::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT { @@ -410,19 +494,19 @@ struct _LIBCPP_TEMPLATE_VIS char_traits typedef u32streampos pos_type; typedef mbstate_t state_type; - static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT - {__c1 = __c2;} + static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 + void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 == __c2;} static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 < __c2;} - _LIBCPP_INLINE_VISIBILITY - static int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY - static size_t length(const char_type* __s) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY - static const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + 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 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY @@ -442,7 +526,7 @@ struct _LIBCPP_TEMPLATE_VIS char_traits {return int_type(0xFFFFFFFF);} }; -inline +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 int char_traits::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT { @@ -456,7 +540,7 @@ char_traits::compare(const char_type* __s1, const char_type* __s2, siz return 0; } -inline +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 size_t char_traits::length(const char_type* __s) _NOEXCEPT { @@ -466,7 +550,7 @@ char_traits::length(const char_type* __s) _NOEXCEPT return __len; } -inline +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 const char32_t* char_traits::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT { diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/assign2.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/assign2.pass.cpp index 2c3deaefd063..311064ceb614 100644 --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/assign2.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/assign2.pass.cpp @@ -11,14 +11,30 @@ // template<> struct char_traits -// static void assign(char_type& c1, const char_type& c2); +// static constexpr void assign(char_type& c1, const char_type& c2); // constexpr in C++17 +// constexpr in C++17 #include #include +#include "test_macros.h" + +#if TEST_STD_VER > 14 +constexpr bool test_constexpr() +{ + char c = '1'; + std::char_traits::assign(c, 'a'); + return c == 'a'; +} +#endif + int main() { char c = '\0'; std::char_traits::assign(c, 'a'); assert(c == 'a'); + +#if TEST_STD_VER > 14 + static_assert(test_constexpr(), "" ); +#endif } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/compare.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/compare.pass.cpp index ba58684b8e2e..71ab24898d60 100644 --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/compare.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/compare.pass.cpp @@ -12,10 +12,22 @@ // template<> struct char_traits // static int compare(const char_type* s1, const char_type* s2, size_t n); +// constexpr in C++17 #include #include +#include "test_macros.h" + +#if TEST_STD_VER > 14 +constexpr bool test_constexpr() +{ + return std::char_traits::compare("123", "223", 3) < 0 + && std::char_traits::compare("223", "123", 3) > 0 + && std::char_traits::compare("123", "123", 3) == 0; +} +#endif + int main() { assert(std::char_traits::compare("", "", 0) == 0); @@ -38,4 +50,8 @@ int main() assert(std::char_traits::compare("223", "123", 3) > 0); assert(std::char_traits::compare("133", "123", 3) > 0); assert(std::char_traits::compare("124", "123", 3) > 0); + +#if TEST_STD_VER > 14 + static_assert(test_constexpr(), "" ); +#endif } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/find.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/find.pass.cpp index a640af28d8ac..714202e25685 100644 --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/find.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/find.pass.cpp @@ -12,10 +12,24 @@ // template<> struct char_traits // static const char_type* find(const char_type* s, size_t n, const char_type& a); +// constexpr in C++17 #include #include +#include "test_macros.h" + +#if TEST_STD_VER > 14 +constexpr bool test_constexpr() +{ + constexpr const char *p = "123"; + return std::char_traits::find(p, 3, '1') == p + && std::char_traits::find(p, 3, '2') == p + 1 + && std::char_traits::find(p, 3, '3') == p + 2 + && std::char_traits::find(p, 3, '4') == nullptr; +} +#endif + int main() { char s1[] = {1, 2, 3}; @@ -25,4 +39,8 @@ int main() assert(std::char_traits::find(s1, 3, char(4)) == 0); assert(std::char_traits::find(s1, 3, char(0)) == 0); assert(std::char_traits::find(NULL, 0, char(0)) == 0); + +#if TEST_STD_VER > 14 + static_assert(test_constexpr(), "" ); +#endif } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/length.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/length.pass.cpp index 56844ef46644..d93e499873b6 100644 --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/length.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/length.pass.cpp @@ -12,10 +12,22 @@ // template<> struct char_traits // static size_t length(const char_type* s); +// constexpr in C++17 #include #include +#include "test_macros.h" + +#if TEST_STD_VER > 14 +constexpr bool test_constexpr() +{ + return std::char_traits::length("") == 0 + && std::char_traits::length("abcd") == 4; +} +#endif + + int main() { assert(std::char_traits::length("") == 0); @@ -23,4 +35,8 @@ int main() assert(std::char_traits::length("aa") == 2); assert(std::char_traits::length("aaa") == 3); assert(std::char_traits::length("aaaa") == 4); + +#if TEST_STD_VER > 14 + static_assert(test_constexpr(), "" ); +#endif } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign2.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign2.pass.cpp index 7f223af57414..e28f906c05bb 100644 --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign2.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign2.pass.cpp @@ -12,12 +12,22 @@ // template<> struct char_traits // static void assign(char_type& c1, const char_type& c2); +// constexpr in C++17 #include #include #include "test_macros.h" +#if TEST_STD_VER > 14 +constexpr bool test_constexpr() +{ + char16_t c = u'1'; + std::char_traits::assign(c, u'a'); + return c == u'a'; +} +#endif + int main() { #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS @@ -26,5 +36,9 @@ int main() std::char_traits::assign(c, u'a'); assert(c == u'a'); #endif + +#if TEST_STD_VER > 14 + static_assert(test_constexpr(), "" ); +#endif #endif // _LIBCPP_HAS_NO_UNICODE_CHARS } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/compare.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/compare.pass.cpp index 7356097a6677..b4be1402ad1c 100644 --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/compare.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/compare.pass.cpp @@ -12,12 +12,23 @@ // template<> struct char_traits // static int compare(const char_type* s1, const char_type* s2, size_t n); +// constexpr in C++17 #include #include #include "test_macros.h" +#if TEST_STD_VER > 14 +constexpr bool test_constexpr() +{ + return std::char_traits::compare(u"123", u"223", 3) < 0 + && std::char_traits::compare(u"223", u"123", 3) > 0 + && std::char_traits::compare(u"123", u"123", 3) == 0; +} +#endif + + int main() { #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS @@ -43,5 +54,9 @@ int main() assert(std::char_traits::compare(u"133", u"123", 3) > 0); assert(std::char_traits::compare(u"124", u"123", 3) > 0); #endif + +#if TEST_STD_VER > 14 + static_assert(test_constexpr(), "" ); +#endif #endif // _LIBCPP_HAS_NO_UNICODE_CHARS } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/find.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/find.pass.cpp index 22db05b55a87..852451cb827e 100644 --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/find.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/find.pass.cpp @@ -12,10 +12,24 @@ // template<> struct char_traits // static const char_type* find(const char_type* s, size_t n, const char_type& a); +// constexpr in C++17 #include #include +#include "test_macros.h" + +#if TEST_STD_VER > 14 +constexpr bool test_constexpr() +{ + constexpr const char16_t *p = u"123"; + return std::char_traits::find(p, 3, u'1') == p + && std::char_traits::find(p, 3, u'2') == p + 1 + && std::char_traits::find(p, 3, u'3') == p + 2 + && std::char_traits::find(p, 3, u'4') == nullptr; +} +#endif + int main() { #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS @@ -26,5 +40,9 @@ int main() assert(std::char_traits::find(s1, 3, char16_t(4)) == 0); assert(std::char_traits::find(s1, 3, char16_t(0)) == 0); assert(std::char_traits::find(NULL, 0, char16_t(0)) == 0); + +#if TEST_STD_VER > 14 + static_assert(test_constexpr(), "" ); +#endif #endif // _LIBCPP_HAS_NO_UNICODE_CHARS } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/length.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/length.pass.cpp index ff5a2a934a9f..5d882bde2f5a 100644 --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/length.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/length.pass.cpp @@ -12,12 +12,21 @@ // template<> struct char_traits // static size_t length(const char_type* s); +// constexpr in C++17 #include #include #include "test_macros.h" +#if TEST_STD_VER > 14 +constexpr bool test_constexpr() +{ + return std::char_traits::length(u"") == 0 + && std::char_traits::length(u"abcd") == 4; +} +#endif + int main() { #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS @@ -28,5 +37,9 @@ int main() assert(std::char_traits::length(u"aaa") == 3); assert(std::char_traits::length(u"aaaa") == 4); #endif + +#if TEST_STD_VER > 14 + static_assert(test_constexpr(), "" ); +#endif #endif // _LIBCPP_HAS_NO_UNICODE_CHARS } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign2.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign2.pass.cpp index 6cd55ea58bff..373931169d81 100644 --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign2.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign2.pass.cpp @@ -12,12 +12,22 @@ // template<> struct char_traits // static void assign(char_type& c1, const char_type& c2); +// constexpr in C++17 #include #include #include "test_macros.h" +#if TEST_STD_VER > 14 +constexpr bool test_constexpr() +{ + char32_t c = U'1'; + std::char_traits::assign(c, U'a'); + return c == U'a'; +} +#endif + int main() { #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS @@ -26,5 +36,9 @@ int main() std::char_traits::assign(c, U'a'); assert(c == U'a'); #endif + +#if TEST_STD_VER > 14 + static_assert(test_constexpr(), "" ); +#endif #endif // _LIBCPP_HAS_NO_UNICODE_CHARS } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/compare.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/compare.pass.cpp index 2671b5624100..1730d06cc16a 100644 --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/compare.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/compare.pass.cpp @@ -12,12 +12,22 @@ // template<> struct char_traits // static int compare(const char_type* s1, const char_type* s2, size_t n); +// constexpr in C++17 #include #include #include "test_macros.h" +#if TEST_STD_VER > 14 +constexpr bool test_constexpr() +{ + return std::char_traits::compare(U"123", U"223", 3) < 0 + && std::char_traits::compare(U"223", U"123", 3) > 0 + && std::char_traits::compare(U"123", U"123", 3) == 0; +} +#endif + int main() { #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS @@ -43,5 +53,9 @@ int main() assert(std::char_traits::compare(U"133", U"123", 3) > 0); assert(std::char_traits::compare(U"124", U"123", 3) > 0); #endif + +#if TEST_STD_VER > 14 + static_assert(test_constexpr(), "" ); +#endif #endif // _LIBCPP_HAS_NO_UNICODE_CHARS } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/find.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/find.pass.cpp index d0b17999d3e1..6d201db62efc 100644 --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/find.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/find.pass.cpp @@ -12,10 +12,24 @@ // template<> struct char_traits // static const char_type* find(const char_type* s, size_t n, const char_type& a); +// constexpr in C++17 #include #include +#include "test_macros.h" + +#if TEST_STD_VER > 14 +constexpr bool test_constexpr() +{ + constexpr const char32_t *p = U"123"; + return std::char_traits::find(p, 3, U'1') == p + && std::char_traits::find(p, 3, U'2') == p + 1 + && std::char_traits::find(p, 3, U'3') == p + 2 + && std::char_traits::find(p, 3, U'4') == nullptr; +} +#endif + int main() { #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS @@ -26,5 +40,9 @@ int main() assert(std::char_traits::find(s1, 3, char32_t(4)) == 0); assert(std::char_traits::find(s1, 3, char32_t(0)) == 0); assert(std::char_traits::find(NULL, 0, char32_t(0)) == 0); + +#if TEST_STD_VER > 14 + static_assert(test_constexpr(), "" ); +#endif #endif // _LIBCPP_HAS_NO_UNICODE_CHARS } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/length.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/length.pass.cpp index e0bee5dc5080..9d691aca4ec9 100644 --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/length.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/length.pass.cpp @@ -12,12 +12,21 @@ // template<> struct char_traits // static size_t length(const char_type* s); +// constexpr in C++17 #include #include #include "test_macros.h" +#if TEST_STD_VER > 14 +constexpr bool test_constexpr() +{ + return std::char_traits::length(U"") == 0 + && std::char_traits::length(U"abcd") == 4; +} +#endif + int main() { #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS @@ -28,5 +37,9 @@ int main() assert(std::char_traits::length(U"aaa") == 3); assert(std::char_traits::length(U"aaaa") == 4); #endif + +#if TEST_STD_VER > 14 + static_assert(test_constexpr(), "" ); +#endif #endif // _LIBCPP_HAS_NO_UNICODE_CHARS } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/assign2.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/assign2.pass.cpp index 7dcf08c2e76f..7a317f0d66de 100644 --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/assign2.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/assign2.pass.cpp @@ -12,13 +12,29 @@ // template<> struct char_traits // static void assign(char_type& c1, const char_type& c2); +// constexpr in C++17 #include #include +#include "test_macros.h" + +#if TEST_STD_VER > 14 +constexpr bool test_constexpr() +{ + wchar_t c = L'1'; + std::char_traits::assign(c, L'a'); + return c == L'a'; +} +#endif + int main() { wchar_t c = L'\0'; std::char_traits::assign(c, L'a'); assert(c == L'a'); + +#if TEST_STD_VER > 14 + static_assert(test_constexpr(), "" ); +#endif } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/compare.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/compare.pass.cpp index 124201bb82f3..894560d69396 100644 --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/compare.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/compare.pass.cpp @@ -12,10 +12,22 @@ // template<> struct char_traits // static int compare(const char_type* s1, const char_type* s2, size_t n); +// constexpr in C++17 #include #include +#include "test_macros.h" + +#if TEST_STD_VER > 14 +constexpr bool test_constexpr() +{ + return std::char_traits::compare(L"123", L"223", 3) < 0 + && std::char_traits::compare(L"223", L"123", 3) > 0 + && std::char_traits::compare(L"123", L"123", 3) == 0; +} +#endif + int main() { assert(std::char_traits::compare(L"", L"", 0) == 0); @@ -38,4 +50,8 @@ int main() assert(std::char_traits::compare(L"223", L"123", 3) > 0); assert(std::char_traits::compare(L"133", L"123", 3) > 0); assert(std::char_traits::compare(L"124", L"123", 3) > 0); + +#if TEST_STD_VER > 14 + static_assert(test_constexpr(), "" ); +#endif } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/find.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/find.pass.cpp index ead3f32fcc72..80aca0ea7f9d 100644 --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/find.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/find.pass.cpp @@ -12,10 +12,24 @@ // template<> struct char_traits // static const char_type* find(const char_type* s, size_t n, const char_type& a); +// constexpr in C++17 #include #include +#include "test_macros.h" + +#if TEST_STD_VER > 14 +constexpr bool test_constexpr() +{ + constexpr const wchar_t *p = L"123"; + return std::char_traits::find(p, 3, L'1') == p + && std::char_traits::find(p, 3, L'2') == p + 1 + && std::char_traits::find(p, 3, L'3') == p + 2 + && std::char_traits::find(p, 3, L'4') == nullptr; +} +#endif + int main() { wchar_t s1[] = {1, 2, 3}; @@ -25,4 +39,8 @@ int main() assert(std::char_traits::find(s1, 3, wchar_t(4)) == 0); assert(std::char_traits::find(s1, 3, wchar_t(0)) == 0); assert(std::char_traits::find(NULL, 0, wchar_t(0)) == 0); + +#if TEST_STD_VER > 14 + static_assert(test_constexpr(), "" ); +#endif } diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/length.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/length.pass.cpp index 691e968ed246..35cbb2d5fd47 100644 --- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/length.pass.cpp +++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/length.pass.cpp @@ -12,10 +12,21 @@ // template<> struct char_traits // static size_t length(const char_type* s); +// constexpr in C++17 #include #include +#include "test_macros.h" + +#if TEST_STD_VER > 14 +constexpr bool test_constexpr() +{ + return std::char_traits::length(L"") == 0 + && std::char_traits::length(L"abcd") == 4; +} +#endif + int main() { assert(std::char_traits::length(L"") == 0); @@ -23,4 +34,8 @@ int main() assert(std::char_traits::length(L"aa") == 2); assert(std::char_traits::length(L"aaa") == 3); assert(std::char_traits::length(L"aaaa") == 4); + +#if TEST_STD_VER > 14 + static_assert(test_constexpr(), "" ); +#endif }