1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
14 #include <type_traits>
16 #include "test_macros.h"
19 #error NULL not defined
23 #error WCHAR_MAX not defined
27 #error WCHAR_MIN not defined
31 #error WEOF not defined
36 // mbstate_t comes from the underlying C library; it is defined (in C99) as:
37 // a complete object type other than an array type that can hold the conversion
38 // state information necessary to convert between sequences of multibyte
39 // characters and wide characters
48 ((void)mb
); // Prevent unused warning
49 ((void)s
); // Prevent unused warning
50 ((void)tm
); // Prevent unused warning
51 ((void)w
); // Prevent unused warning
52 ((void)fp
); // Prevent unused warning
53 ((void)va
); // Prevent unused warning
54 ((void)ns
); // Prevent unused warning
55 ((void)ws
); // Prevent unused warning
56 static_assert((std::is_same
<decltype(fwprintf(fp
, L
"")), int>::value
), "");
57 static_assert((std::is_same
<decltype(fwscanf(fp
, L
"")), int>::value
), "");
58 static_assert((std::is_same
<decltype(swprintf(ws
, s
, L
"")), int>::value
), "");
59 static_assert((std::is_same
<decltype(swscanf(L
"", L
"")), int>::value
), "");
60 static_assert((std::is_same
<decltype(vfwprintf(fp
, L
"", va
)), int>::value
), "");
61 static_assert((std::is_same
<decltype(vfwscanf(fp
, L
"", va
)), int>::value
), "");
62 static_assert((std::is_same
<decltype(vswprintf(ws
, s
, L
"", va
)), int>::value
), "");
63 static_assert((std::is_same
<decltype(vswscanf(L
"", L
"", va
)), int>::value
), "");
64 static_assert((std::is_same
<decltype(fgetwc(fp
)), wint_t>::value
), "");
65 static_assert((std::is_same
<decltype(fgetws(ws
, 0, fp
)), wchar_t*>::value
), "");
66 static_assert((std::is_same
<decltype(fputwc(L
' ', fp
)), wint_t>::value
), "");
67 static_assert((std::is_same
<decltype(fputws(L
"", fp
)), int>::value
), "");
68 static_assert((std::is_same
<decltype(fwide(fp
, 0)), int>::value
), "");
69 static_assert((std::is_same
<decltype(getwc(fp
)), wint_t>::value
), "");
70 static_assert((std::is_same
<decltype(putwc(L
' ', fp
)), wint_t>::value
), "");
71 static_assert((std::is_same
<decltype(ungetwc(L
' ', fp
)), wint_t>::value
), "");
72 static_assert((std::is_same
<decltype(wcstod(L
"", (wchar_t**)0)), double>::value
), "");
73 static_assert((std::is_same
<decltype(wcstof(L
"", (wchar_t**)0)), float>::value
), "");
74 static_assert((std::is_same
<decltype(wcstold(L
"", (wchar_t**)0)), long double>::value
), "");
75 static_assert((std::is_same
<decltype(wcstol(L
"", (wchar_t**)0, 0)), long>::value
), "");
76 static_assert((std::is_same
<decltype(wcstoll(L
"", (wchar_t**)0, 0)), long long>::value
), "");
77 static_assert((std::is_same
<decltype(wcstoul(L
"", (wchar_t**)0, 0)), unsigned long>::value
), "");
78 static_assert((std::is_same
<decltype(wcstoull(L
"", (wchar_t**)0, 0)), unsigned long long>::value
), "");
79 static_assert((std::is_same
<decltype(wcscpy(ws
, L
"")), wchar_t*>::value
), "");
80 static_assert((std::is_same
<decltype(wcsncpy(ws
, L
"", s
)), wchar_t*>::value
), "");
81 static_assert((std::is_same
<decltype(wcscat(ws
, L
"")), wchar_t*>::value
), "");
82 static_assert((std::is_same
<decltype(wcsncat(ws
, L
"", s
)), wchar_t*>::value
), "");
83 static_assert((std::is_same
<decltype(wcscmp(L
"", L
"")), int>::value
), "");
84 static_assert((std::is_same
<decltype(wcscoll(L
"", L
"")), int>::value
), "");
85 static_assert((std::is_same
<decltype(wcsncmp(L
"", L
"", s
)), int>::value
), "");
86 static_assert((std::is_same
<decltype(wcsxfrm(ws
, L
"", s
)), size_t>::value
), "");
87 static_assert((std::is_same
<decltype(wcschr((wchar_t*)0, L
' ')), wchar_t*>::value
), "");
88 static_assert((std::is_same
<decltype(wcscspn(L
"", L
"")), size_t>::value
), "");
89 static_assert((std::is_same
<decltype(wcslen(L
"")), size_t>::value
), "");
90 static_assert((std::is_same
<decltype(wcspbrk((wchar_t*)0, L
"")), wchar_t*>::value
), "");
91 static_assert((std::is_same
<decltype(wcsrchr((wchar_t*)0, L
' ')), wchar_t*>::value
), "");
92 static_assert((std::is_same
<decltype(wcsspn(L
"", L
"")), size_t>::value
), "");
93 static_assert((std::is_same
<decltype(wcsstr((wchar_t*)0, L
"")), wchar_t*>::value
), "");
94 static_assert((std::is_same
<decltype(wcstok(ws
, L
"", (wchar_t**)0)), wchar_t*>::value
), "");
95 static_assert((std::is_same
<decltype(wmemchr((wchar_t*)0, L
' ', s
)), wchar_t*>::value
), "");
96 static_assert((std::is_same
<decltype(wmemcmp(L
"", L
"", s
)), int>::value
), "");
97 static_assert((std::is_same
<decltype(wmemcpy(ws
, L
"", s
)), wchar_t*>::value
), "");
98 static_assert((std::is_same
<decltype(wmemmove(ws
, L
"", s
)), wchar_t*>::value
), "");
99 static_assert((std::is_same
<decltype(wmemset(ws
, L
' ', s
)), wchar_t*>::value
), "");
100 static_assert((std::is_same
<decltype(wcsftime(ws
, s
, L
"", tm
)), size_t>::value
), "");
101 static_assert((std::is_same
<decltype(btowc(0)), wint_t>::value
), "");
102 static_assert((std::is_same
<decltype(wctob(w
)), int>::value
), "");
103 static_assert((std::is_same
<decltype(mbsinit(&mb
)), int>::value
), "");
104 static_assert((std::is_same
<decltype(mbrlen("", s
, &mb
)), size_t>::value
), "");
105 static_assert((std::is_same
<decltype(mbrtowc(ws
, "", s
, &mb
)), size_t>::value
), "");
106 static_assert((std::is_same
<decltype(wcrtomb(ns
, L
' ', &mb
)), size_t>::value
), "");
107 static_assert((std::is_same
<decltype(mbsrtowcs(ws
, (const char**)0, s
, &mb
)), size_t>::value
), "");
108 static_assert((std::is_same
<decltype(wcsrtombs(ns
, (const wchar_t**)0, s
, &mb
)), size_t>::value
), "");
110 // These tests fail on systems whose C library doesn't provide a correct overload
111 // set for wcschr, wcspbrk, wcsrchr, wcsstr, and wmemchr, unless the compiler is
112 // a suitably recent version of Clang.
113 #if !defined(__APPLE__) || defined(_LIBCPP_PREFERRED_OVERLOAD)
114 static_assert((std::is_same
<decltype(wcschr((const wchar_t*)0, L
' ')), const wchar_t*>::value
), "");
115 static_assert((std::is_same
<decltype(wcspbrk((const wchar_t*)0, L
"")), const wchar_t*>::value
), "");
116 static_assert((std::is_same
<decltype(wcsrchr((const wchar_t*)0, L
' ')), const wchar_t*>::value
), "");
117 static_assert((std::is_same
<decltype(wcsstr((const wchar_t*)0, L
"")), const wchar_t*>::value
), "");
118 static_assert((std::is_same
<decltype(wmemchr((const wchar_t*)0, L
' ', s
)), const wchar_t*>::value
), "");
121 #ifndef _LIBCPP_HAS_NO_STDIN
122 static_assert((std::is_same
<decltype(getwchar()), wint_t>::value
), "");
123 static_assert((std::is_same
<decltype(vwscanf(L
"", va
)), int>::value
), "");
124 static_assert((std::is_same
<decltype(wscanf(L
"")), int>::value
), "");
127 #ifndef _LIBCPP_HAS_NO_STDOUT
128 static_assert((std::is_same
<decltype(putwchar(L
' ')), wint_t>::value
), "");
129 static_assert((std::is_same
<decltype(vwprintf(L
"", va
)), int>::value
), "");
130 static_assert((std::is_same
<decltype(wprintf(L
"")), int>::value
), "");