xref: /llvm-project/clang/test/Sema/wchar.c (revision 8869ba366268c644200784b15c4e6b8efe891397)
1 // RUN: %clang_cc1 %s -fsyntax-only -verify
2 // RUN: %clang_cc1 %s -fsyntax-only -fwchar-type=short -fno-signed-wchar -verify -DSHORT_WCHAR
3 
4 typedef __WCHAR_TYPE__ wchar_t;
5 
6 #if defined(_WIN32) || defined(_M_IX86) || defined(__CYGWIN__) \
7  || defined(_M_X64) || defined(__ORBIS__) || defined(__PROSPERO__) \
8  || defined(SHORT_WCHAR) || (defined(_AIX) && !defined(__64BIT__))
9   #define WCHAR_T_TYPE unsigned short
10 #elif defined(__aarch64__)
11   // See AArch64TargetInfo constructor -- unsigned on non-darwin non-OpenBSD non-NetBSD.
12   #if defined(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__)
13     #define WCHAR_T_TYPE int
14   #else
15     #define WCHAR_T_TYPE unsigned int
16   #endif
17 #elif defined(__arm) || defined(__MVS__) || (defined(_AIX) && defined(__64BIT__))
18   #define WCHAR_T_TYPE unsigned int
19 #elif defined(__sun)
20   #if defined(__LP64__)
21     #define WCHAR_T_TYPE int
22   #else
23     #define WCHAR_T_TYPE long
24   #endif
25 #else /* Solaris, Linux, non-arm64 macOS, ... */
26   #define WCHAR_T_TYPE int
27 #endif
28 
29 int check_wchar_size[sizeof(*L"") == sizeof(wchar_t) ? 1 : -1];
30 
foo(void)31 void foo(void) {
32   WCHAR_T_TYPE t1[] = L"x";
33   wchar_t tab[] = L"x";
34   WCHAR_T_TYPE t2[] = "x";     // expected-error {{initializing wide char array with non-wide string literal}}
35   char t3[] = L"x";   // expected-error {{initializing char array with wide string literal}}
36 }
37