1 | //===----------------------------------------------------------------------===// |
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // XFAIL: no-wide-characters |
10 | |
11 | // <wchar.h> |
12 | |
13 | #include <wchar.h> |
14 | #include <stdarg.h> |
15 | #include <stdio.h> |
16 | #include <type_traits> |
17 | |
18 | #include "test_macros.h" |
19 | |
20 | #ifndef NULL |
21 | #error NULL not defined |
22 | #endif |
23 | |
24 | #ifndef WCHAR_MAX |
25 | #error WCHAR_MAX not defined |
26 | #endif |
27 | |
28 | #ifndef WCHAR_MIN |
29 | #error WCHAR_MIN not defined |
30 | #endif |
31 | |
32 | #ifndef WEOF |
33 | #error WEOF not defined |
34 | #endif |
35 | |
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 |
40 | mbstate_t mb = {}; |
41 | size_t s = 0; |
42 | tm *tm = 0; |
43 | wint_t w = 0; |
44 | ::FILE* fp = 0; |
45 | ::va_list va; |
46 | char* ns = 0; |
47 | wchar_t* ws = 0; |
48 | const wchar_t* cws = 0; |
49 | wchar_t** wsp = 0; |
50 | |
51 | ASSERT_SAME_TYPE(int, decltype(fwprintf(stream: fp, format: L"" ))); |
52 | ASSERT_SAME_TYPE(int, decltype(fwscanf(stream: fp, format: L"" ))); |
53 | ASSERT_SAME_TYPE(int, decltype(swprintf(s: ws, n: s, format: L"" ))); |
54 | ASSERT_SAME_TYPE(int, decltype(swscanf(s: L"" , format: L"" ))); |
55 | ASSERT_SAME_TYPE(int, decltype(vfwprintf(s: fp, format: L"" , arg: va))); |
56 | ASSERT_SAME_TYPE(int, decltype(vfwscanf(s: fp, format: L"" , arg: va))); |
57 | ASSERT_SAME_TYPE(int, decltype(vswprintf(s: ws, n: s, format: L"" , arg: va))); |
58 | ASSERT_SAME_TYPE(int, decltype(vswscanf(s: L"" , format: L"" , arg: va))); |
59 | ASSERT_SAME_TYPE(wint_t, decltype(fgetwc(stream: fp))); |
60 | ASSERT_SAME_TYPE(wchar_t*, decltype(fgetws(ws: ws, n: 0, stream: fp))); |
61 | ASSERT_SAME_TYPE(wint_t, decltype(fputwc(wc: L' ', stream: fp))); |
62 | ASSERT_SAME_TYPE(int, decltype(fputws(ws: L"" , stream: fp))); |
63 | ASSERT_SAME_TYPE(int, decltype(fwide(fp: fp, mode: 0))); |
64 | ASSERT_SAME_TYPE(wint_t, decltype(getwc(stream: fp))); |
65 | ASSERT_SAME_TYPE(wint_t, decltype(putwc(wc: L' ', stream: fp))); |
66 | ASSERT_SAME_TYPE(wint_t, decltype(ungetwc(wc: L' ', stream: fp))); |
67 | ASSERT_SAME_TYPE(double, decltype(wcstod(nptr: L"" , endptr: wsp))); |
68 | ASSERT_SAME_TYPE(float, decltype(wcstof(nptr: L"" , endptr: wsp))); |
69 | ASSERT_SAME_TYPE(long double, decltype(wcstold(nptr: L"" , endptr: wsp))); |
70 | ASSERT_SAME_TYPE(long, decltype(wcstol(nptr: L"" , endptr: wsp, base: 0))); |
71 | ASSERT_SAME_TYPE(long long, decltype(wcstoll(nptr: L"" , endptr: wsp, base: 0))); |
72 | ASSERT_SAME_TYPE(unsigned long, decltype(wcstoul(nptr: L"" , endptr: wsp, base: 0))); |
73 | ASSERT_SAME_TYPE(unsigned long long, decltype(wcstoull(nptr: L"" , endptr: wsp, base: 0))); |
74 | ASSERT_SAME_TYPE(wchar_t*, decltype(wcscpy(dest: ws, src: L"" ))); |
75 | ASSERT_SAME_TYPE(wchar_t*, decltype(wcsncpy(dest: ws, src: L"" , n: s))); |
76 | ASSERT_SAME_TYPE(wchar_t*, decltype(wcscat(dest: ws, src: L"" ))); |
77 | ASSERT_SAME_TYPE(wchar_t*, decltype(wcsncat(dest: ws, src: L"" , n: s))); |
78 | ASSERT_SAME_TYPE(int, decltype(wcscmp(s1: L"" , s2: L"" ))); |
79 | ASSERT_SAME_TYPE(int, decltype(wcscoll(s1: L"" , s2: L"" ))); |
80 | ASSERT_SAME_TYPE(int, decltype(wcsncmp(s1: L"" , s2: L"" , n: s))); |
81 | ASSERT_SAME_TYPE(size_t, decltype(wcsxfrm(s1: ws, s2: L"" , n: s))); |
82 | ASSERT_SAME_TYPE(wchar_t*, decltype(wcschr(wcs: ws, wc: L' '))); |
83 | ASSERT_SAME_TYPE(const wchar_t*, decltype(wcschr(wcs: cws, wc: L' '))); |
84 | ASSERT_SAME_TYPE(size_t, decltype(wcscspn(wcs: L"" , reject: L"" ))); |
85 | ASSERT_SAME_TYPE(size_t, decltype(wcslen(s: L"" ))); |
86 | ASSERT_SAME_TYPE(wchar_t*, decltype(wcspbrk(wcs: ws, accept: L"" ))); |
87 | ASSERT_SAME_TYPE(const wchar_t*, decltype(wcspbrk(wcs: cws, accept: L"" ))); |
88 | ASSERT_SAME_TYPE(wchar_t*, decltype(wcsrchr(wcs: ws, wc: L' '))); |
89 | ASSERT_SAME_TYPE(const wchar_t*, decltype(wcsrchr(wcs: cws, wc: L' '))); |
90 | ASSERT_SAME_TYPE(size_t, decltype(wcsspn(wcs: L"" , accept: L"" ))); |
91 | ASSERT_SAME_TYPE(wchar_t*, decltype(wcsstr(haystack: ws, needle: L"" ))); |
92 | ASSERT_SAME_TYPE(const wchar_t*, decltype(wcsstr(haystack: cws, needle: L"" ))); |
93 | ASSERT_SAME_TYPE(wchar_t*, decltype(wcstok(s: ws, delim: L"" , ptr: wsp))); |
94 | ASSERT_SAME_TYPE(wchar_t*, decltype(wmemchr(s: ws, c: L' ', n: s))); |
95 | ASSERT_SAME_TYPE(const wchar_t*, decltype(wmemchr(s: cws, c: L' ', n: s))); |
96 | ASSERT_SAME_TYPE(int, decltype(wmemcmp(s1: L"" , s2: L"" , n: s))); |
97 | ASSERT_SAME_TYPE(wchar_t*, decltype(wmemcpy(s1: ws, s2: L"" , n: s))); |
98 | ASSERT_SAME_TYPE(wchar_t*, decltype(wmemmove(s1: ws, s2: L"" , n: s))); |
99 | ASSERT_SAME_TYPE(wchar_t*, decltype(wmemset(s: ws, c: L' ', n: s))); |
100 | ASSERT_SAME_TYPE(size_t, decltype(wcsftime(s: ws, maxsize: s, format: L"" , tp: tm))); |
101 | ASSERT_SAME_TYPE(wint_t, decltype(btowc(c: 0))); |
102 | ASSERT_SAME_TYPE(int, decltype(wctob(c: w))); |
103 | ASSERT_SAME_TYPE(int, decltype(mbsinit(ps: &mb))); |
104 | ASSERT_SAME_TYPE(size_t, decltype(mbrlen(s: "" , n: s, ps: &mb))); |
105 | ASSERT_SAME_TYPE(size_t, decltype(mbrtowc(pwc: ws, s: "" , n: s, p: &mb))); |
106 | ASSERT_SAME_TYPE(size_t, decltype(wcrtomb(s: ns, wc: L' ', ps: &mb))); |
107 | ASSERT_SAME_TYPE(size_t, decltype(mbsrtowcs(dst: ws, src: (const char**)0, len: s, ps: &mb))); |
108 | ASSERT_SAME_TYPE(size_t, decltype(wcsrtombs(dst: ns, src: (const wchar_t**)0, len: s, ps: &mb))); |
109 | ASSERT_SAME_TYPE(wint_t, decltype(getwchar())); |
110 | ASSERT_SAME_TYPE(int, decltype(vwscanf(format: L"" , arg: va))); |
111 | ASSERT_SAME_TYPE(int, decltype(wscanf(format: L"" ))); |
112 | ASSERT_SAME_TYPE(wint_t, decltype(putwchar(wc: L' '))); |
113 | ASSERT_SAME_TYPE(int, decltype(vwprintf(format: L"" , arg: va))); |
114 | ASSERT_SAME_TYPE(int, decltype(wprintf(format: L"" ))); |
115 | |