[libcxx] r260337 - Fix overload sets of strchr, strpbrk, strrchr, memchr and strstr from

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 9 16:59:02 PST 2016


Author: rsmith
Date: Tue Feb  9 18:59:02 2016
New Revision: 260337

URL: http://llvm.org/viewvc/llvm-project?rev=260337&view=rev
Log:
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.

Added:
    libcxx/trunk/include/string.h
      - copied, changed from r251642, libcxx/trunk/include/string.h
Modified:
    libcxx/trunk/include/__config
    libcxx/trunk/include/cstring
    libcxx/trunk/include/cwchar
    libcxx/trunk/include/wchar.h
    libcxx/trunk/test/std/depr/depr.c.headers/string_h.pass.cpp
    libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp
    libcxx/trunk/test/std/strings/c.strings/cstring.pass.cpp
    libcxx/trunk/test/std/strings/c.strings/cwchar.pass.cpp

Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=260337&r1=260336&r2=260337&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Tue Feb  9 18:59:02 2016
@@ -237,6 +237,12 @@
 #  endif
 #endif
 
+#ifndef _LIBCPP_PREFERRED_OVERLOAD
+#  if __has_attribute(__enable_if__)
+#    define _LIBCPP_PREFERRED_OVERLOAD __attribute__ ((__enable_if__(true, "")))
+#  endif
+#endif
+
 #ifndef _LIBCPP_TYPE_VIS_ONLY
 # define _LIBCPP_TYPE_VIS_ONLY _LIBCPP_TYPE_VIS
 #endif

Modified: libcxx/trunk/include/cstring
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cstring?rev=260337&r1=260336&r2=260337&view=diff
==============================================================================
--- libcxx/trunk/include/cstring (original)
+++ libcxx/trunk/include/cstring Tue Feb  9 18:59:02 2016
@@ -78,30 +78,13 @@ using ::strcmp;
 using ::strncmp;
 using ::strcoll;
 using ::strxfrm;
-
 using ::memchr;
-
 using ::strchr;
-
 using ::strcspn;
-
 using ::strpbrk;
-
 using ::strrchr;
-
 using ::strspn;
-
 using ::strstr;
-
-// MSVCRT, GNU libc and its derivates already have the correct prototype in <string.h> #ifdef __cplusplus
-#if !defined(__GLIBC__) && !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_)
-inline _LIBCPP_INLINE_VISIBILITY       char* strchr(      char* __s, int __c) {return ::strchr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY       char* strpbrk(      char* __s1, const char* __s2) {return ::strpbrk(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY       char* strrchr(      char* __s, int __c) {return ::strrchr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY       void* memchr(      void* __s, int __c, size_t __n) {return ::memchr(__s, __c, __n);}
-inline _LIBCPP_INLINE_VISIBILITY       char* strstr(      char* __s1, const char* __s2) {return ::strstr(__s1, __s2);}
-#endif
-
 #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
 using ::strtok;
 #endif

Modified: libcxx/trunk/include/cwchar
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cwchar?rev=260337&r1=260336&r2=260337&view=diff
==============================================================================
--- libcxx/trunk/include/cwchar (original)
+++ libcxx/trunk/include/cwchar Tue Feb  9 18:59:02 2016
@@ -157,30 +157,11 @@ using ::wcscmp;
 using ::wcscoll;
 using ::wcsncmp;
 using ::wcsxfrm;
-
-#ifdef _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS
 using ::wcschr;
 using ::wcspbrk;
 using ::wcsrchr;
 using ::wcsstr;
 using ::wmemchr;
-#else
-inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {return ::wcschr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wcschr(      wchar_t* __s, wchar_t __c) {return ::wcschr(__s, __c);}
-
-inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return ::wcspbrk(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wcspbrk(      wchar_t* __s1, const wchar_t* __s2) {return ::wcspbrk(__s1, __s2);}
-
-inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcsrchr(const wchar_t* __s, wchar_t __c) {return ::wcsrchr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wcsrchr(      wchar_t* __s, wchar_t __c) {return ::wcsrchr(__s, __c);}
-
-inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return ::wcsstr(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wcsstr(      wchar_t* __s1, const wchar_t* __s2) {return ::wcsstr(__s1, __s2);}
-
-inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
-inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wmemchr(      wchar_t* __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
-#endif
-
 using ::wcscspn;
 using ::wcslen;
 using ::wcsspn;

Copied: libcxx/trunk/include/string.h (from r251642, libcxx/trunk/include/string.h)
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string.h?p2=libcxx/trunk/include/string.h&p1=libcxx/trunk/include/string.h&r1=251642&r2=260337&rev=260337&view=diff
==============================================================================
--- libcxx/trunk/include/string.h (original)
+++ libcxx/trunk/include/string.h Tue Feb  9 18:59:02 2016
@@ -60,4 +60,51 @@ size_t strlen(const char* s);
 
 #include_next <string.h>
 
+// MSVCRT, GNU libc and its derivates already have the correct prototype in
+// <string.h> if __cplusplus is defined. This macro can be defined by users if
+// their C library provides the right signature.
+#if defined(__GLIBC__) || defined(_LIBCPP_MSVCRT) || defined(__sun__) || \
+    defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_)
+#define _LIBCPP_STRING_H_HAS_CONST_OVERLOADS
+#endif
+
+#if defined(__cplusplus) && !defined(_LIBCPP_STRING_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
+extern "C++" {
+inline _LIBCPP_INLINE_VISIBILITY
+char* __libcpp_strchr(const char* __s, int __c) {return (char*)strchr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+const char* strchr(const char* __s, int __c) {return __libcpp_strchr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+      char* strchr(      char* __s, int __c) {return __libcpp_strchr(__s, __c);}
+
+inline _LIBCPP_INLINE_VISIBILITY
+char* __libcpp_strpbrk(const char* __s1, const char* __s2) {return (char*)strpbrk(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+const char* strpbrk(const char* __s1, const char* __s2) {return __libcpp_strpbrk(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+      char* strpbrk(      char* __s1, const char* __s2) {return __libcpp_strpbrk(__s1, __s2);}
+
+inline _LIBCPP_INLINE_VISIBILITY
+char* __libcpp_strrchr(const char* __s, int __c) {return (char*)strrchr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+const char* strrchr(const char* __s, int __c) {return __libcpp_strrchr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+      char* strrchr(      char* __s, int __c) {return __libcpp_strrchr(__s, __c);}
+
+inline _LIBCPP_INLINE_VISIBILITY
+void* __libcpp_memchr(const void* __s, int __c, size_t __n) {return (void*)memchr(__s, __c, __n);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+const void* memchr(const void* __s, int __c, size_t __n) {return __libcpp_memchr(__s, __c, __n);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+      void* memchr(      void* __s, int __c, size_t __n) {return __libcpp_memchr(__s, __c, __n);}
+
+inline _LIBCPP_INLINE_VISIBILITY
+char* __libcpp_strstr(const char* __s1, const char* __s2) {return (char*)strstr(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+const char* strstr(const char* __s1, const char* __s2) {return __libcpp_strstr(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+      char* strstr(      char* __s1, const char* __s2) {return __libcpp_strstr(__s1, __s2);}
+}
+#endif
+
 #endif  // _LIBCPP_STRING_H

Modified: libcxx/trunk/include/wchar.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/wchar.h?rev=260337&r1=260336&r2=260337&view=diff
==============================================================================
--- libcxx/trunk/include/wchar.h (original)
+++ libcxx/trunk/include/wchar.h Tue Feb  9 18:59:02 2016
@@ -118,7 +118,7 @@ size_t wcsrtombs(char* restrict dst, con
 
 #include_next <wchar.h>
 
-// Let <cwchar> know if we have const-correct overloads for wcschr and friends.
+// Determine whether we have const-correct overloads for wcschr and friends.
 #if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
 #  define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
 #elif defined(__GLIBC_PREREQ)
@@ -127,6 +127,45 @@ size_t wcsrtombs(char* restrict dst, con
 #  endif
 #endif
 
+#if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
+extern "C++" {
+inline _LIBCPP_INLINE_VISIBILITY
+wchar_t* __libcpp_wcschr(const wchar_t* __s, wchar_t __c) {return (wchar_t*)wcschr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+      wchar_t* wcschr(      wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);}
+
+inline _LIBCPP_INLINE_VISIBILITY
+wchar_t* __libcpp_wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcspbrk(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+const wchar_t* wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcspbrk(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+      wchar_t* wcspbrk(      wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcspbrk(__s1, __s2);}
+
+inline _LIBCPP_INLINE_VISIBILITY
+wchar_t* __libcpp_wcsrchr(const wchar_t* __s, wchar_t __c) {return (wchar_t*)wcsrchr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+const wchar_t* wcsrchr(const wchar_t* __s, wchar_t __c) {return __libcpp_wcsrchr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+      wchar_t* wcsrchr(      wchar_t* __s, wchar_t __c) {return __libcpp_wcsrchr(__s, __c);}
+
+inline _LIBCPP_INLINE_VISIBILITY
+wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcsstr(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+const wchar_t* wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcsstr(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+      wchar_t* wcsstr(      wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcsstr(__s1, __s2);}
+
+inline _LIBCPP_INLINE_VISIBILITY
+wchar_t* __libcpp_wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return (wchar_t*)wmemchr(__s, __c, __n);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+const wchar_t* wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return __libcpp_wmemchr(__s, __c, __n);}
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
+      wchar_t* wmemchr(      wchar_t* __s, wchar_t __c, size_t __n) {return __libcpp_wmemchr(__s, __c, __n);}
+}
+#endif
+
 #if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT) || defined(__MINGW32__))
 extern "C++" {
 #include <support/win32/support.h> // pull in *swprintf defines

Modified: libcxx/trunk/test/std/depr/depr.c.headers/string_h.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/depr/depr.c.headers/string_h.pass.cpp?rev=260337&r1=260336&r2=260337&view=diff
==============================================================================
--- libcxx/trunk/test/std/depr/depr.c.headers/string_h.pass.cpp (original)
+++ libcxx/trunk/test/std/depr/depr.c.headers/string_h.pass.cpp Tue Feb  9 18:59:02 2016
@@ -47,4 +47,15 @@ int main()
     static_assert((std::is_same<decltype(memset(vp, 0, s)), void*>::value), "");
     static_assert((std::is_same<decltype(strerror(0)), char*>::value), "");
     static_assert((std::is_same<decltype(strlen(cpc)), 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(strchr(cpc, 0)), const char*>::value), "");
+    static_assert((std::is_same<decltype(strpbrk(cpc, cpc)), const char*>::value), "");
+    static_assert((std::is_same<decltype(strrchr(cpc, 0)), const char*>::value), "");
+    static_assert((std::is_same<decltype(strstr(cpc, cpc)), const char*>::value), "");
+    static_assert((std::is_same<decltype(memchr(vpc, 0, s)), const void*>::value), "");
+#endif
 }

Modified: libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp?rev=260337&r1=260336&r2=260337&view=diff
==============================================================================
--- libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp (original)
+++ libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp Tue Feb  9 18:59:02 2016
@@ -9,7 +9,6 @@
 
 // <wchar.h>
 
-
 #include <wchar.h>
 #include <type_traits>
 
@@ -82,19 +81,14 @@ int main()
     static_assert((std::is_same<decltype(wcscoll(L"", L"")), int>::value), "");
     static_assert((std::is_same<decltype(wcsncmp(L"", L"", s)), int>::value), "");
     static_assert((std::is_same<decltype(wcsxfrm(ws, L"", s)), size_t>::value), "");
-    // const wchar_t* wcschr((const wchar_t*)0, L' ') - See below
     static_assert((std::is_same<decltype(wcschr((wchar_t*)0, L' ')), wchar_t*>::value), "");
     static_assert((std::is_same<decltype(wcscspn(L"", L"")), size_t>::value), "");
     static_assert((std::is_same<decltype(wcslen(L"")), size_t>::value), "");
-    // const wchar_t* wcspbrk((const wchar_t*)0, L"") - See below
     static_assert((std::is_same<decltype(wcspbrk((wchar_t*)0, L"")), wchar_t*>::value), "");
-    // const wchar_t* wcsrchr((const wchar_t*)0, L' ') - See below
     static_assert((std::is_same<decltype(wcsrchr((wchar_t*)0, L' ')), wchar_t*>::value), "");
     static_assert((std::is_same<decltype(wcsspn(L"", L"")), size_t>::value), "");
-    // const wchar_t* wcsstr((const wchar_t*)0, L"") - See below
     static_assert((std::is_same<decltype(wcsstr((wchar_t*)0, L"")), wchar_t*>::value), "");
     static_assert((std::is_same<decltype(wcstok(ws, L"", (wchar_t**)0)), wchar_t*>::value), "");
-    // const wchar_t* wmemchr((const wchar_t*)0, L' ', s) - See below
     static_assert((std::is_same<decltype(wmemchr((wchar_t*)0, L' ', s)), wchar_t*>::value), "");
     static_assert((std::is_same<decltype(wmemcmp(L"", L"", s)), int>::value), "");
     static_assert((std::is_same<decltype(wmemcpy(ws, L"", s)), wchar_t*>::value), "");
@@ -110,10 +104,10 @@ int main()
     static_assert((std::is_same<decltype(mbsrtowcs(ws, (const char**)0, s, &mb)), size_t>::value), "");
     static_assert((std::is_same<decltype(wcsrtombs(ns, (const wchar_t**)0, s, &mb)), size_t>::value), "");
 
-// This test fails on systems whose C library doesn't provide a correct overload
-// set for wcschr, wcspbrk, wcsrchr, wcsstr, and wmemchr. There's no way for
-// libc++ to fix that on the C library's behalf.
-#ifndef __APPLE__
+    // 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(wcschr((const wchar_t*)0, L' ')), const wchar_t*>::value), "");
     static_assert((std::is_same<decltype(wcspbrk((const wchar_t*)0, L"")), const wchar_t*>::value), "");
     static_assert((std::is_same<decltype(wcsrchr((const wchar_t*)0, L' ')), const wchar_t*>::value), "");

Modified: libcxx/trunk/test/std/strings/c.strings/cstring.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/c.strings/cstring.pass.cpp?rev=260337&r1=260336&r2=260337&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/c.strings/cstring.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/c.strings/cstring.pass.cpp Tue Feb  9 18:59:02 2016
@@ -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
 }

Modified: libcxx/trunk/test/std/strings/c.strings/cwchar.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/c.strings/cwchar.pass.cpp?rev=260337&r1=260336&r2=260337&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/c.strings/cwchar.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/c.strings/cwchar.pass.cpp Tue Feb  9 18:59:02 2016
@@ -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), "");




More information about the cfe-commits mailing list