forked from OSchip/llvm-project
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
This commit is contained in:
parent
755a4e6b57
commit
5fd17ab1b0
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
// -*- C++ -*-
|
||||
//===--------------------------- string.h ---------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP_STRING_H
|
||||
#define _LIBCPP_STRING_H
|
||||
|
||||
/*
|
||||
string.h synopsis
|
||||
|
||||
Macros:
|
||||
|
||||
NULL
|
||||
|
||||
Types:
|
||||
|
||||
size_t
|
||||
|
||||
void* memcpy(void* restrict s1, const void* restrict s2, size_t n);
|
||||
void* memmove(void* s1, const void* s2, size_t n);
|
||||
char* strcpy (char* restrict s1, const char* restrict s2);
|
||||
char* strncpy(char* restrict s1, const char* restrict s2, size_t n);
|
||||
char* strcat (char* restrict s1, const char* restrict s2);
|
||||
char* strncat(char* restrict s1, const char* restrict s2, size_t n);
|
||||
int memcmp(const void* s1, const void* s2, size_t n);
|
||||
int strcmp (const char* s1, const char* s2);
|
||||
int strncmp(const char* s1, const char* s2, size_t n);
|
||||
int strcoll(const char* s1, const char* s2);
|
||||
size_t strxfrm(char* restrict s1, const char* restrict s2, size_t n);
|
||||
const void* memchr(const void* s, int c, size_t n);
|
||||
void* memchr( void* s, int c, size_t n);
|
||||
const char* strchr(const char* s, int c);
|
||||
char* strchr( char* s, int c);
|
||||
size_t strcspn(const char* s1, const char* s2);
|
||||
const char* strpbrk(const char* s1, const char* s2);
|
||||
char* strpbrk( char* s1, const char* s2);
|
||||
const char* strrchr(const char* s, int c);
|
||||
char* strrchr( char* s, int c);
|
||||
size_t strspn(const char* s1, const char* s2);
|
||||
const char* strstr(const char* s1, const char* s2);
|
||||
char* strstr( char* s1, const char* s2);
|
||||
char* strtok(char* restrict s1, const char* restrict s2);
|
||||
void* memset(void* s, int c, size_t n);
|
||||
char* strerror(int errnum);
|
||||
size_t strlen(const char* s);
|
||||
|
||||
*/
|
||||
|
||||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#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
|
|
@ -118,7 +118,7 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
|
|||
|
||||
#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, const wchar_t** restrict src, size_t len,
|
|||
# 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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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), "");
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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), "");
|
||||
|
|
Loading…
Reference in New Issue