Index: include/__string =================================================================== --- include/__string +++ include/__string @@ -26,13 +26,14 @@ 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 @@ 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 @@ }; 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 @@ 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 @@ 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 @@ 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,47 @@ {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 +} + + +// 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 _LIBCPP_STD_VER <= 14 +// return memcmp(__s1, __s2, __n); +// #else +// for (; __n; --__n, ++__s1, ++__s2) +// { +// if (lt(*__s1, *__s2)) +// return -1; +// if (lt(*__s2, *__s1)) +// return 1; +// } +// return 0; +// #endif +// } + + // char_traits template <> @@ -245,19 +290,19 @@ 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 +325,66 @@ {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,20 +396,20 @@ 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 _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 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 char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; @@ -323,7 +428,7 @@ {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 +442,7 @@ return 0; } -inline +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 size_t char_traits::length(const char_type* __s) _NOEXCEPT { @@ -347,7 +452,7 @@ 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,20 +515,20 @@ 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 _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 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 char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; @@ -442,7 +547,7 @@ {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 +561,7 @@ return 0; } -inline +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 size_t char_traits::length(const char_type* __s) _NOEXCEPT { @@ -466,7 +571,7 @@ 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 { Index: test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/assign2.pass.cpp =================================================================== --- test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/assign2.pass.cpp +++ 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 } Index: test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/compare.pass.cpp =================================================================== --- test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/compare.pass.cpp +++ 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 @@ 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 } Index: test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/find.pass.cpp =================================================================== --- test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/find.pass.cpp +++ 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 @@ 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 } Index: test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/length.pass.cpp =================================================================== --- test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/length.pass.cpp +++ 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 @@ 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 } Index: test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign2.pass.cpp =================================================================== --- test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign2.pass.cpp +++ test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign2.pass.cpp @@ -12,6 +12,7 @@ // template<> struct char_traits // static void assign(char_type& c1, const char_type& c2); +// constexpr in C++17 #include #include @@ -18,6 +19,15 @@ #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 @@ 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 } Index: test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/compare.pass.cpp =================================================================== --- test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/compare.pass.cpp +++ test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/compare.pass.cpp @@ -12,6 +12,7 @@ // template<> struct char_traits // static int compare(const char_type* s1, const char_type* s2, size_t n); +// constexpr in C++17 #include #include @@ -18,6 +19,16 @@ #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 @@ 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 } Index: test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/find.pass.cpp =================================================================== --- test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/find.pass.cpp +++ 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 @@ 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 } Index: test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/length.pass.cpp =================================================================== --- test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/length.pass.cpp +++ test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/length.pass.cpp @@ -12,6 +12,7 @@ // template<> struct char_traits // static size_t length(const char_type* s); +// constexpr in C++17 #include #include @@ -18,6 +19,14 @@ #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 @@ 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 } Index: test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign2.pass.cpp =================================================================== --- test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign2.pass.cpp +++ test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign2.pass.cpp @@ -12,6 +12,7 @@ // template<> struct char_traits // static void assign(char_type& c1, const char_type& c2); +// constexpr in C++17 #include #include @@ -18,6 +19,15 @@ #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 @@ 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 } Index: test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/compare.pass.cpp =================================================================== --- test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/compare.pass.cpp +++ test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/compare.pass.cpp @@ -12,6 +12,7 @@ // template<> struct char_traits // static int compare(const char_type* s1, const char_type* s2, size_t n); +// constexpr in C++17 #include #include @@ -18,6 +19,15 @@ #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 @@ 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 } Index: test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/find.pass.cpp =================================================================== --- test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/find.pass.cpp +++ 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 @@ 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 } Index: test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/length.pass.cpp =================================================================== --- test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/length.pass.cpp +++ test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/length.pass.cpp @@ -12,6 +12,7 @@ // template<> struct char_traits // static size_t length(const char_type* s); +// constexpr in C++17 #include #include @@ -18,6 +19,14 @@ #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 @@ 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 } Index: test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/assign2.pass.cpp =================================================================== --- test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/assign2.pass.cpp +++ 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 } Index: test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/compare.pass.cpp =================================================================== --- test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/compare.pass.cpp +++ 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 @@ 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 } Index: test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/find.pass.cpp =================================================================== --- test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/find.pass.cpp +++ 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 @@ 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 } Index: test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/length.pass.cpp =================================================================== --- test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/length.pass.cpp +++ 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 @@ 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 }