summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/strings/c.strings/cstring.pass.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2016-02-10 00:59:02 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2016-02-10 00:59:02 +0000
commit5fd17ab1b093f6b59aabb27f6c2c2278e65c2707 (patch)
treecb54a6dfa5d6d92ab253e36c131c5dceb30a29de /libcxx/test/std/strings/c.strings/cstring.pass.cpp
parent755a4e6b5736fca0d41c13856a7a34780c0cbd64 (diff)
downloadbcm5719-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/cstring.pass.cpp')
-rw-r--r--libcxx/test/std/strings/c.strings/cstring.pass.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/libcxx/test/std/strings/c.strings/cstring.pass.cpp b/libcxx/test/std/strings/c.strings/cstring.pass.cpp
index 20f4050cfbd..63f86d35061 100644
--- a/libcxx/test/std/strings/c.strings/cstring.pass.cpp
+++ b/libcxx/test/std/strings/c.strings/cstring.pass.cpp
@@ -34,17 +34,12 @@ int main()
static_assert((std::is_same<decltype(std::strncmp(cpc, cpc, s)), int>::value), "");
static_assert((std::is_same<decltype(std::strcoll(cpc, cpc)), int>::value), "");
static_assert((std::is_same<decltype(std::strxfrm(cp, cpc, s)), std::size_t>::value), "");
-// static_assert((std::is_same<decltype(std::memchr(vpc, 0, s)), const void*>::value), "");
static_assert((std::is_same<decltype(std::memchr(vp, 0, s)), void*>::value), "");
-// static_assert((std::is_same<decltype(std::strchr(cpc, 0)), const char*>::value), "");
static_assert((std::is_same<decltype(std::strchr(cp, 0)), char*>::value), "");
static_assert((std::is_same<decltype(std::strcspn(cpc, cpc)), std::size_t>::value), "");
-// static_assert((std::is_same<decltype(std::strpbrk(cpc, cpc)), const char*>::value), "");
static_assert((std::is_same<decltype(std::strpbrk(cp, cpc)), char*>::value), "");
-// static_assert((std::is_same<decltype(std::strrchr(cpc, 0)), const char*>::value), "");
static_assert((std::is_same<decltype(std::strrchr(cp, 0)), char*>::value), "");
static_assert((std::is_same<decltype(std::strspn(cpc, cpc)), std::size_t>::value), "");
-// static_assert((std::is_same<decltype(std::strstr(cpc, cpc)), const char*>::value), "");
static_assert((std::is_same<decltype(std::strstr(cp, cpc)), char*>::value), "");
#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
static_assert((std::is_same<decltype(std::strtok(cp, cpc)), char*>::value), "");
@@ -52,4 +47,15 @@ int main()
static_assert((std::is_same<decltype(std::memset(vp, 0, s)), void*>::value), "");
static_assert((std::is_same<decltype(std::strerror(0)), char*>::value), "");
static_assert((std::is_same<decltype(std::strlen(cpc)), std::size_t>::value), "");
+
+ // These tests fail on systems whose C library doesn't provide a correct overload
+ // set for strchr, strpbrk, strrchr, strstr, and memchr, unless the compiler is
+ // a suitably recent version of Clang.
+#if !defined(__APPLE__) || defined(_LIBCPP_PREFERRED_OVERLOAD)
+ static_assert((std::is_same<decltype(std::memchr(vpc, 0, s)), const void*>::value), "");
+ static_assert((std::is_same<decltype(std::strchr(cpc, 0)), const char*>::value), "");
+ static_assert((std::is_same<decltype(std::strpbrk(cpc, cpc)), const char*>::value), "");
+ static_assert((std::is_same<decltype(std::strrchr(cpc, 0)), const char*>::value), "");
+ static_assert((std::is_same<decltype(std::strstr(cpc, cpc)), const char*>::value), "");
+#endif
}
OpenPOWER on IntegriCloud