diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-02-10 00:59:02 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-02-10 00:59:02 +0000 |
commit | 5fd17ab1b093f6b59aabb27f6c2c2278e65c2707 (patch) | |
tree | cb54a6dfa5d6d92ab253e36c131c5dceb30a29de /libcxx/test/std/strings/c.strings/cwchar.pass.cpp | |
parent | 755a4e6b5736fca0d41c13856a7a34780c0cbd64 (diff) | |
download | bcm5719-llvm-5fd17ab1b093f6b59aabb27f6c2c2278e65c2707.tar.gz bcm5719-llvm-5fd17ab1b093f6b59aabb27f6c2c2278e65c2707.zip |
Fix overload sets of strchr, strpbrk, strrchr, memchr and strstr from
<string.h> and wcschr, wcspbrk, wcsrchr, wmemchr, and wcsstr from <wchar.h> to
provide a const-correct overload set even when the underlying C library does
not.
This change adds a new macro, _LIBCPP_PREFERRED_OVERLOAD, which (if defined)
specifies that a given overload is a better match than an otherwise equally
good function declaration without the overload. This is implemented in modern
versions of Clang via __attribute__((enable_if)), and not elsewhere.
We use this new macro to define overloads in the global namespace for these
functions that displace the overloads provided by the C library, unless we
believe the C library is already providing the correct signatures.
llvm-svn: 260337
Diffstat (limited to 'libcxx/test/std/strings/c.strings/cwchar.pass.cpp')
-rw-r--r-- | libcxx/test/std/strings/c.strings/cwchar.pass.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/libcxx/test/std/strings/c.strings/cwchar.pass.cpp b/libcxx/test/std/strings/c.strings/cwchar.pass.cpp index 93d2bb1efa5..85b861017fd 100644 --- a/libcxx/test/std/strings/c.strings/cwchar.pass.cpp +++ b/libcxx/test/std/strings/c.strings/cwchar.pass.cpp @@ -73,19 +73,14 @@ int main() static_assert((std::is_same<decltype(std::wcscoll(L"", L"")), int>::value), ""); static_assert((std::is_same<decltype(std::wcsncmp(L"", L"", s)), int>::value), ""); static_assert((std::is_same<decltype(std::wcsxfrm(ws, L"", s)), std::size_t>::value), ""); - static_assert((std::is_same<decltype(std::wcschr((const wchar_t*)0, L' ')), const wchar_t*>::value), ""); static_assert((std::is_same<decltype(std::wcschr((wchar_t*)0, L' ')), wchar_t*>::value), ""); static_assert((std::is_same<decltype(std::wcscspn(L"", L"")), std::size_t>::value), ""); static_assert((std::is_same<decltype(std::wcslen(L"")), std::size_t>::value), ""); - static_assert((std::is_same<decltype(std::wcspbrk((const wchar_t*)0, L"")), const wchar_t*>::value), ""); static_assert((std::is_same<decltype(std::wcspbrk((wchar_t*)0, L"")), wchar_t*>::value), ""); - static_assert((std::is_same<decltype(std::wcsrchr((const wchar_t*)0, L' ')), const wchar_t*>::value), ""); static_assert((std::is_same<decltype(std::wcsrchr((wchar_t*)0, L' ')), wchar_t*>::value), ""); static_assert((std::is_same<decltype(std::wcsspn(L"", L"")), std::size_t>::value), ""); - static_assert((std::is_same<decltype(std::wcsstr((const wchar_t*)0, L"")), const wchar_t*>::value), ""); static_assert((std::is_same<decltype(std::wcsstr((wchar_t*)0, L"")), wchar_t*>::value), ""); static_assert((std::is_same<decltype(std::wcstok(ws, L"", (wchar_t**)0)), wchar_t*>::value), ""); - static_assert((std::is_same<decltype(std::wmemchr((const wchar_t*)0, L' ', s)), const wchar_t*>::value), ""); static_assert((std::is_same<decltype(std::wmemchr((wchar_t*)0, L' ', s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(std::wmemcmp(L"", L"", s)), int>::value), ""); static_assert((std::is_same<decltype(std::wmemcpy(ws, L"", s)), wchar_t*>::value), ""); @@ -101,6 +96,17 @@ int main() static_assert((std::is_same<decltype(std::mbsrtowcs(ws, (const char**)0, s, &mb)), std::size_t>::value), ""); static_assert((std::is_same<decltype(std::wcsrtombs(ns, (const wchar_t**)0, s, &mb)), std::size_t>::value), ""); + // These tests fail on systems whose C library doesn't provide a correct overload + // set for wcschr, wcspbrk, wcsrchr, wcsstr, and wmemchr, unless the compiler is + // a suitably recent version of Clang. +#if !defined(__APPLE__) || defined(_LIBCPP_PREFERRED_OVERLOAD) + static_assert((std::is_same<decltype(std::wcschr((const wchar_t*)0, L' ')), const wchar_t*>::value), ""); + static_assert((std::is_same<decltype(std::wcspbrk((const wchar_t*)0, L"")), const wchar_t*>::value), ""); + static_assert((std::is_same<decltype(std::wcsrchr((const wchar_t*)0, L' ')), const wchar_t*>::value), ""); + static_assert((std::is_same<decltype(std::wcsstr((const wchar_t*)0, L"")), const wchar_t*>::value), ""); + static_assert((std::is_same<decltype(std::wmemchr((const wchar_t*)0, L' ', s)), const wchar_t*>::value), ""); +#endif + #ifndef _LIBCPP_HAS_NO_STDIN static_assert((std::is_same<decltype(std::getwchar()), std::wint_t>::value), ""); static_assert((std::is_same<decltype(std::vwscanf(L"", va)), int>::value), ""); |