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// <cwchar>
10
11// XFAIL: no-wide-characters
12
13#include <cwchar>
14#include <ctime>
15#include <cstdarg>
16#include <cstdio>
17#include <type_traits>
18
19#include "test_macros.h"
20
21#ifndef NULL
22# error NULL not defined
23#endif
24
25#ifndef WCHAR_MAX
26# error WCHAR_MAX not defined
27#endif
28
29#ifndef WCHAR_MIN
30# error WCHAR_MIN not defined
31#endif
32
33#ifndef WEOF
34# error WEOF not defined
35#endif
36
37int main(int, char**) {
38 std::mbstate_t mb = {};
39 std::size_t s = 0;
40 std::tm* tm = 0;
41 std::wint_t w = 0;
42 ::FILE* fp = 0;
43 std::va_list va;
44
45 char* ns = 0;
46 wchar_t* ws = 0;
47 const wchar_t* cws = 0;
48 wchar_t** wsp = 0;
49
50 ((void)mb); // Prevent unused warning
51 ((void)s); // Prevent unused warning
52 ((void)tm); // Prevent unused warning
53 ((void)w); // Prevent unused warning
54 ((void)fp); // Prevent unused warning
55 ((void)va); // Prevent unused warning
56 ((void)ns); // Prevent unused warning
57 ((void)ws); // Prevent unused warning
58 ((void)cws); // Prevent unused warning
59 ((void)wsp); // Prevent unused warning
60
61 ASSERT_SAME_TYPE(int, decltype(std::fwprintf(fp, L"")));
62 ASSERT_SAME_TYPE(int, decltype(std::fwscanf(fp, L"")));
63 ASSERT_SAME_TYPE(int, decltype(std::swprintf(ws, s, L"")));
64 ASSERT_SAME_TYPE(int, decltype(std::swscanf(L"", L"")));
65 ASSERT_SAME_TYPE(int, decltype(std::vfwprintf(fp, L"", va)));
66 ASSERT_SAME_TYPE(int, decltype(std::vfwscanf(fp, L"", va)));
67 ASSERT_SAME_TYPE(int, decltype(std::vswprintf(ws, s, L"", va)));
68 ASSERT_SAME_TYPE(int, decltype(std::vswscanf(L"", L"", va)));
69 ASSERT_SAME_TYPE(std::wint_t, decltype(std::fgetwc(fp)));
70 ASSERT_SAME_TYPE(wchar_t*, decltype(std::fgetws(ws, 0, fp)));
71 ASSERT_SAME_TYPE(std::wint_t, decltype(std::fputwc(L' ', fp)));
72 ASSERT_SAME_TYPE(int, decltype(std::fputws(L"", fp)));
73 ASSERT_SAME_TYPE(int, decltype(std::fwide(fp, 0)));
74 ASSERT_SAME_TYPE(std::wint_t, decltype(std::getwc(fp)));
75 ASSERT_SAME_TYPE(std::wint_t, decltype(std::putwc(L' ', fp)));
76 ASSERT_SAME_TYPE(std::wint_t, decltype(std::ungetwc(L' ', fp)));
77 ASSERT_SAME_TYPE(double, decltype(std::wcstod(L"", wsp)));
78 ASSERT_SAME_TYPE(float, decltype(std::wcstof(L"", wsp)));
79 ASSERT_SAME_TYPE(long double, decltype(std::wcstold(L"", wsp)));
80 ASSERT_SAME_TYPE(long, decltype(std::wcstol(L"", wsp, 0)));
81 ASSERT_SAME_TYPE(long long, decltype(std::wcstoll(L"", wsp, 0)));
82 ASSERT_SAME_TYPE(unsigned long, decltype(std::wcstoul(L"", wsp, 0)));
83 ASSERT_SAME_TYPE(unsigned long long, decltype(std::wcstoull(L"", wsp, 0)));
84 ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcscpy(ws, L"")));
85 ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcsncpy(ws, L"", s)));
86 ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcscat(ws, L"")));
87 ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcsncat(ws, L"", s)));
88 ASSERT_SAME_TYPE(int, decltype(std::wcscmp(L"", L"")));
89 ASSERT_SAME_TYPE(int, decltype(std::wcscoll(L"", L"")));
90 ASSERT_SAME_TYPE(int, decltype(std::wcsncmp(L"", L"", s)));
91 ASSERT_SAME_TYPE(std::size_t, decltype(std::wcsxfrm(ws, L"", s)));
92 ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcschr(ws, L' ')));
93 ASSERT_SAME_TYPE(const wchar_t*, decltype(std::wcschr(cws, L' ')));
94 ASSERT_SAME_TYPE(std::size_t, decltype(std::wcscspn(L"", L"")));
95 ASSERT_SAME_TYPE(std::size_t, decltype(std::wcslen(L"")));
96 ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcspbrk(ws, L"")));
97 ASSERT_SAME_TYPE(const wchar_t*, decltype(std::wcspbrk(cws, L"")));
98 ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcsrchr(ws, L' ')));
99 ASSERT_SAME_TYPE(const wchar_t*, decltype(std::wcsrchr(cws, L' ')));
100 ASSERT_SAME_TYPE(std::size_t, decltype(std::wcsspn(L"", L"")));
101 ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcsstr(ws, L"")));
102 ASSERT_SAME_TYPE(const wchar_t*, decltype(std::wcsstr(cws, L"")));
103 ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcstok(ws, L"", wsp)));
104 ASSERT_SAME_TYPE(wchar_t*, decltype(std::wmemchr(ws, L' ', s)));
105 ASSERT_SAME_TYPE(const wchar_t*, decltype(std::wmemchr(cws, L' ', s)));
106 ASSERT_SAME_TYPE(int, decltype(std::wmemcmp(L"", L"", s)));
107 ASSERT_SAME_TYPE(wchar_t*, decltype(std::wmemcpy(ws, L"", s)));
108 ASSERT_SAME_TYPE(wchar_t*, decltype(std::wmemmove(ws, L"", s)));
109 ASSERT_SAME_TYPE(wchar_t*, decltype(std::wmemset(ws, L' ', s)));
110 ASSERT_SAME_TYPE(std::size_t, decltype(std::wcsftime(ws, s, L"", tm)));
111 ASSERT_SAME_TYPE(wint_t, decltype(std::btowc(0)));
112 ASSERT_SAME_TYPE(int, decltype(std::wctob(w)));
113 ASSERT_SAME_TYPE(int, decltype(std::mbsinit(&mb)));
114 ASSERT_SAME_TYPE(std::size_t, decltype(std::mbrlen("", s, &mb)));
115 ASSERT_SAME_TYPE(std::size_t, decltype(std::mbrtowc(ws, "", s, &mb)));
116 ASSERT_SAME_TYPE(std::size_t, decltype(std::wcrtomb(ns, L' ', &mb)));
117 ASSERT_SAME_TYPE(std::size_t, decltype(std::mbsrtowcs(ws, (const char**)0, s, &mb)));
118 ASSERT_SAME_TYPE(std::size_t, decltype(std::wcsrtombs(ns, (const wchar_t**)0, s, &mb)));
119
120 ASSERT_SAME_TYPE(std::wint_t, decltype(std::getwchar()));
121 ASSERT_SAME_TYPE(int, decltype(std::vwscanf(L"", va)));
122 ASSERT_SAME_TYPE(int, decltype(std::wscanf(L"")));
123
124 ASSERT_SAME_TYPE(std::wint_t, decltype(std::putwchar(L' ')));
125 ASSERT_SAME_TYPE(int, decltype(std::vwprintf(L"", va)));
126 ASSERT_SAME_TYPE(int, decltype(std::wprintf(L"")));
127
128 return 0;
129}
130

source code of libcxx/test/std/strings/c.strings/cwchar.pass.cpp