xref: /aosp_15_r20/external/clang/test/SemaCXX/no-wchar.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -triple i386-pc-win32 -fsyntax-only -fno-wchar -verify %s
2*67e74705SXin Li wchar_t x; // expected-error {{unknown type name 'wchar_t'}}
3*67e74705SXin Li 
4*67e74705SXin Li typedef unsigned short wchar_t;
5*67e74705SXin Li void foo(const wchar_t* x);
6*67e74705SXin Li 
bar()7*67e74705SXin Li void bar() {
8*67e74705SXin Li   foo(L"wide string literal");
9*67e74705SXin Li }
10*67e74705SXin Li 
11*67e74705SXin Li void foo1(wchar_t * t = L"");
12*67e74705SXin Li // expected-warning@-1 {{conversion from string literal to 'wchar_t *' (aka 'unsigned short *') is deprecated}}
13*67e74705SXin Li 
14*67e74705SXin Li short *a = L"";
15*67e74705SXin Li // expected-error@-1 {{cannot initialize a variable of type 'short *' with an lvalue of type 'const unsigned short [1]'}}
16*67e74705SXin Li char *b = L"";
17*67e74705SXin Li // expected-error@-1 {{cannot initialize a variable of type 'char *' with an lvalue of type 'const unsigned short [1]'}}
18*67e74705SXin Li 
19*67e74705SXin Li // NOTE: MSVC allows deprecated conversion in conditional expression if at least
20*67e74705SXin Li // one of the operand is a string literal but Clang doesn't allow it.
21*67e74705SXin Li wchar_t *c = true ? L"a" : L"";
22*67e74705SXin Li // expected-error@-1 {{cannot initialize a variable of type 'wchar_t *' (aka 'unsigned short *') with}}
23*67e74705SXin Li 
24*67e74705SXin Li const wchar_t *d1 = 0;
25*67e74705SXin Li const wchar_t *d2 = 0;
26*67e74705SXin Li wchar_t *d = true ? d1 : d2;
27*67e74705SXin Li // expected-error@-1 {{cannot initialize a variable of type 'wchar_t *' (aka 'unsigned short *') with}}
28*67e74705SXin Li 
29*67e74705SXin Li wchar_t* e = (const wchar_t*)L"";
30*67e74705SXin Li // expected-error@-1 {{cannot initialize a variable of type 'wchar_t *' (aka 'unsigned short *') with an rvalue of type 'const wchar_t *' (aka 'const unsigned short *')}}
31