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
40mbstate_t mb = {};
41size_t s = 0;
42tm *tm = 0;
43wint_t w = 0;
44::FILE* fp = 0;
45::va_list va;
46char* ns = 0;
47wchar_t* ws = 0;
48const wchar_t* cws = 0;
49wchar_t** wsp = 0;
50
51ASSERT_SAME_TYPE(int, decltype(fwprintf(stream: fp, format: L"")));
52ASSERT_SAME_TYPE(int, decltype(fwscanf(stream: fp, format: L"")));
53ASSERT_SAME_TYPE(int, decltype(swprintf(s: ws, n: s, format: L"")));
54ASSERT_SAME_TYPE(int, decltype(swscanf(s: L"", format: L"")));
55ASSERT_SAME_TYPE(int, decltype(vfwprintf(s: fp, format: L"", arg: va)));
56ASSERT_SAME_TYPE(int, decltype(vfwscanf(s: fp, format: L"", arg: va)));
57ASSERT_SAME_TYPE(int, decltype(vswprintf(s: ws, n: s, format: L"", arg: va)));
58ASSERT_SAME_TYPE(int, decltype(vswscanf(s: L"", format: L"", arg: va)));
59ASSERT_SAME_TYPE(wint_t, decltype(fgetwc(stream: fp)));
60ASSERT_SAME_TYPE(wchar_t*, decltype(fgetws(ws: ws, n: 0, stream: fp)));
61ASSERT_SAME_TYPE(wint_t, decltype(fputwc(wc: L' ', stream: fp)));
62ASSERT_SAME_TYPE(int, decltype(fputws(ws: L"", stream: fp)));
63ASSERT_SAME_TYPE(int, decltype(fwide(fp: fp, mode: 0)));
64ASSERT_SAME_TYPE(wint_t, decltype(getwc(stream: fp)));
65ASSERT_SAME_TYPE(wint_t, decltype(putwc(wc: L' ', stream: fp)));
66ASSERT_SAME_TYPE(wint_t, decltype(ungetwc(wc: L' ', stream: fp)));
67ASSERT_SAME_TYPE(double, decltype(wcstod(nptr: L"", endptr: wsp)));
68ASSERT_SAME_TYPE(float, decltype(wcstof(nptr: L"", endptr: wsp)));
69ASSERT_SAME_TYPE(long double, decltype(wcstold(nptr: L"", endptr: wsp)));
70ASSERT_SAME_TYPE(long, decltype(wcstol(nptr: L"", endptr: wsp, base: 0)));
71ASSERT_SAME_TYPE(long long, decltype(wcstoll(nptr: L"", endptr: wsp, base: 0)));
72ASSERT_SAME_TYPE(unsigned long, decltype(wcstoul(nptr: L"", endptr: wsp, base: 0)));
73ASSERT_SAME_TYPE(unsigned long long, decltype(wcstoull(nptr: L"", endptr: wsp, base: 0)));
74ASSERT_SAME_TYPE(wchar_t*, decltype(wcscpy(dest: ws, src: L"")));
75ASSERT_SAME_TYPE(wchar_t*, decltype(wcsncpy(dest: ws, src: L"", n: s)));
76ASSERT_SAME_TYPE(wchar_t*, decltype(wcscat(dest: ws, src: L"")));
77ASSERT_SAME_TYPE(wchar_t*, decltype(wcsncat(dest: ws, src: L"", n: s)));
78ASSERT_SAME_TYPE(int, decltype(wcscmp(s1: L"", s2: L"")));
79ASSERT_SAME_TYPE(int, decltype(wcscoll(s1: L"", s2: L"")));
80ASSERT_SAME_TYPE(int, decltype(wcsncmp(s1: L"", s2: L"", n: s)));
81ASSERT_SAME_TYPE(size_t, decltype(wcsxfrm(s1: ws, s2: L"", n: s)));
82ASSERT_SAME_TYPE(wchar_t*, decltype(wcschr(wcs: ws, wc: L' ')));
83ASSERT_SAME_TYPE(const wchar_t*, decltype(wcschr(wcs: cws, wc: L' ')));
84ASSERT_SAME_TYPE(size_t, decltype(wcscspn(wcs: L"", reject: L"")));
85ASSERT_SAME_TYPE(size_t, decltype(wcslen(s: L"")));
86ASSERT_SAME_TYPE(wchar_t*, decltype(wcspbrk(wcs: ws, accept: L"")));
87ASSERT_SAME_TYPE(const wchar_t*, decltype(wcspbrk(wcs: cws, accept: L"")));
88ASSERT_SAME_TYPE(wchar_t*, decltype(wcsrchr(wcs: ws, wc: L' ')));
89ASSERT_SAME_TYPE(const wchar_t*, decltype(wcsrchr(wcs: cws, wc: L' ')));
90ASSERT_SAME_TYPE(size_t, decltype(wcsspn(wcs: L"", accept: L"")));
91ASSERT_SAME_TYPE(wchar_t*, decltype(wcsstr(haystack: ws, needle: L"")));
92ASSERT_SAME_TYPE(const wchar_t*, decltype(wcsstr(haystack: cws, needle: L"")));
93ASSERT_SAME_TYPE(wchar_t*, decltype(wcstok(s: ws, delim: L"", ptr: wsp)));
94ASSERT_SAME_TYPE(wchar_t*, decltype(wmemchr(s: ws, c: L' ', n: s)));
95ASSERT_SAME_TYPE(const wchar_t*, decltype(wmemchr(s: cws, c: L' ', n: s)));
96ASSERT_SAME_TYPE(int, decltype(wmemcmp(s1: L"", s2: L"", n: s)));
97ASSERT_SAME_TYPE(wchar_t*, decltype(wmemcpy(s1: ws, s2: L"", n: s)));
98ASSERT_SAME_TYPE(wchar_t*, decltype(wmemmove(s1: ws, s2: L"", n: s)));
99ASSERT_SAME_TYPE(wchar_t*, decltype(wmemset(s: ws, c: L' ', n: s)));
100ASSERT_SAME_TYPE(size_t, decltype(wcsftime(s: ws, maxsize: s, format: L"", tp: tm)));
101ASSERT_SAME_TYPE(wint_t, decltype(btowc(c: 0)));
102ASSERT_SAME_TYPE(int, decltype(wctob(c: w)));
103ASSERT_SAME_TYPE(int, decltype(mbsinit(ps: &mb)));
104ASSERT_SAME_TYPE(size_t, decltype(mbrlen(s: "", n: s, ps: &mb)));
105ASSERT_SAME_TYPE(size_t, decltype(mbrtowc(pwc: ws, s: "", n: s, p: &mb)));
106ASSERT_SAME_TYPE(size_t, decltype(wcrtomb(s: ns, wc: L' ', ps: &mb)));
107ASSERT_SAME_TYPE(size_t, decltype(mbsrtowcs(dst: ws, src: (const char**)0, len: s, ps: &mb)));
108ASSERT_SAME_TYPE(size_t, decltype(wcsrtombs(dst: ns, src: (const wchar_t**)0, len: s, ps: &mb)));
109ASSERT_SAME_TYPE(wint_t, decltype(getwchar()));
110ASSERT_SAME_TYPE(int, decltype(vwscanf(format: L"", arg: va)));
111ASSERT_SAME_TYPE(int, decltype(wscanf(format: L"")));
112ASSERT_SAME_TYPE(wint_t, decltype(putwchar(wc: L' ')));
113ASSERT_SAME_TYPE(int, decltype(vwprintf(format: L"", arg: va)));
114ASSERT_SAME_TYPE(int, decltype(wprintf(format: L"")));
115

source code of libcxx/test/std/depr/depr.c.headers/wchar_h.compile.pass.cpp