xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/format-strings-ms.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -fms-compatibility -triple=i386-pc-win32 %s
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -fms-compatibility -triple=i386-pc-win32 -Wformat-non-iso -DNON_ISO_WARNING %s
3f4a2713aSLionel Sambuc 
4f4a2713aSLionel Sambuc int printf(const char *format, ...) __attribute__((format(printf, 1, 2)));
5*0a6a1f1dSLionel Sambuc int scanf(const char * restrict, ...) ;
6*0a6a1f1dSLionel Sambuc typedef unsigned short wchar_t;
7*0a6a1f1dSLionel Sambuc 
8*0a6a1f1dSLionel Sambuc #ifdef NON_ISO_WARNING
9*0a6a1f1dSLionel Sambuc 
10*0a6a1f1dSLionel Sambuc // Split off this test to reduce the warning noise in the rest of the file.
non_iso_warning_test(__int32 i32,__int64 i64,wchar_t c,void * p)11*0a6a1f1dSLionel Sambuc void non_iso_warning_test(__int32 i32, __int64 i64, wchar_t c, void *p) {
12*0a6a1f1dSLionel Sambuc   printf("%Id", i32); // expected-warning{{'I' length modifier is not supported by ISO C}}
13*0a6a1f1dSLionel Sambuc   printf("%I32d", i32); // expected-warning{{'I32' length modifier is not supported by ISO C}}
14*0a6a1f1dSLionel Sambuc   printf("%I64d", i64); // expected-warning{{'I64' length modifier is not supported by ISO C}}
15*0a6a1f1dSLionel Sambuc   printf("%wc", c); // expected-warning{{'w' length modifier is not supported by ISO C}}
16*0a6a1f1dSLionel Sambuc   printf("%Z", p); // expected-warning{{'Z' conversion specifier is not supported by ISO C}}
17*0a6a1f1dSLionel Sambuc }
18*0a6a1f1dSLionel Sambuc 
19*0a6a1f1dSLionel Sambuc #else
20f4a2713aSLionel Sambuc 
signed_test()21f4a2713aSLionel Sambuc void signed_test() {
22f4a2713aSLionel Sambuc   short val = 30;
23*0a6a1f1dSLionel Sambuc   printf("val = %I64d\n", val); // expected-warning{{format specifies type '__int64' (aka 'long long') but the argument has type 'short'}}
24f4a2713aSLionel Sambuc   long long bigval = 30;
25*0a6a1f1dSLionel Sambuc   printf("val = %I32d\n", bigval); // expected-warning{{format specifies type '__int32' (aka 'int') but the argument has type 'long long'}}
26*0a6a1f1dSLionel Sambuc   printf("val = %Id\n", bigval); // expected-warning{{format specifies type '__int32' (aka 'int') but the argument has type 'long long'}}
27f4a2713aSLionel Sambuc }
28f4a2713aSLionel Sambuc 
unsigned_test()29f4a2713aSLionel Sambuc void unsigned_test() {
30f4a2713aSLionel Sambuc   unsigned short val = 30;
31*0a6a1f1dSLionel Sambuc   printf("val = %I64u\n", val); // expected-warning{{format specifies type 'unsigned __int64' (aka 'unsigned long long') but the argument has type 'unsigned short'}}
32f4a2713aSLionel Sambuc   unsigned long long bigval = 30;
33*0a6a1f1dSLionel Sambuc   printf("val = %I32u\n", bigval); // expected-warning{{format specifies type 'unsigned __int32' (aka 'unsigned int') but the argument has type 'unsigned long long'}}
34*0a6a1f1dSLionel Sambuc   printf("val = %Iu\n", bigval); // expected-warning{{format specifies type 'unsigned __int32' (aka 'unsigned int') but the argument has type 'unsigned long long'}}
35f4a2713aSLionel Sambuc }
36*0a6a1f1dSLionel Sambuc 
w_test(wchar_t c,wchar_t * s)37*0a6a1f1dSLionel Sambuc void w_test(wchar_t c, wchar_t *s) {
38*0a6a1f1dSLionel Sambuc   printf("%wc", c);
39*0a6a1f1dSLionel Sambuc   printf("%wC", c);
40*0a6a1f1dSLionel Sambuc   printf("%C", c);
41*0a6a1f1dSLionel Sambuc   printf("%ws", s);
42*0a6a1f1dSLionel Sambuc   printf("%wS", s);
43*0a6a1f1dSLionel Sambuc   printf("%S", s);
44*0a6a1f1dSLionel Sambuc   scanf("%wc", &c);
45*0a6a1f1dSLionel Sambuc   scanf("%wC", &c);
46*0a6a1f1dSLionel Sambuc   scanf("%C", &c);
47*0a6a1f1dSLionel Sambuc   scanf("%ws", s);
48*0a6a1f1dSLionel Sambuc   scanf("%wS", s);
49*0a6a1f1dSLionel Sambuc   scanf("%S", s);
50*0a6a1f1dSLionel Sambuc 
51*0a6a1f1dSLionel Sambuc   double bad;
52*0a6a1f1dSLionel Sambuc   printf("%wc", bad); // expected-warning{{format specifies type 'wint_t' (aka 'int') but the argument has type 'double'}}
53*0a6a1f1dSLionel Sambuc   printf("%wC", bad); // expected-warning{{format specifies type 'wchar_t' (aka 'unsigned short') but the argument has type 'double'}}
54*0a6a1f1dSLionel Sambuc   printf("%C", bad); // expected-warning{{format specifies type 'wchar_t' (aka 'unsigned short') but the argument has type 'double'}}
55*0a6a1f1dSLionel Sambuc   printf("%ws", bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double'}}
56*0a6a1f1dSLionel Sambuc   printf("%wS", bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double'}}
57*0a6a1f1dSLionel Sambuc   printf("%S", bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double'}}
58*0a6a1f1dSLionel Sambuc   scanf("%wc", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
59*0a6a1f1dSLionel Sambuc   scanf("%wC", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
60*0a6a1f1dSLionel Sambuc   scanf("%C", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
61*0a6a1f1dSLionel Sambuc   scanf("%ws", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
62*0a6a1f1dSLionel Sambuc   scanf("%wS", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
63*0a6a1f1dSLionel Sambuc   scanf("%S", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
64*0a6a1f1dSLionel Sambuc 
65*0a6a1f1dSLionel Sambuc }
66*0a6a1f1dSLionel Sambuc 
h_test(char c,char * s)67*0a6a1f1dSLionel Sambuc void h_test(char c, char* s) {
68*0a6a1f1dSLionel Sambuc   double bad;
69*0a6a1f1dSLionel Sambuc   printf("%hc", bad); // expected-warning{{format specifies type 'int' but the argument has type 'double'}}
70*0a6a1f1dSLionel Sambuc   printf("%hC", bad); // expected-warning{{format specifies type 'int' but the argument has type 'double'}}
71*0a6a1f1dSLionel Sambuc   printf("%hs", bad); // expected-warning{{format specifies type 'char *' but the argument has type 'double'}}
72*0a6a1f1dSLionel Sambuc   printf("%hS", bad); // expected-warning{{format specifies type 'char *' but the argument has type 'double'}}
73*0a6a1f1dSLionel Sambuc   scanf("%hc", &bad); // expected-warning{{format specifies type 'char *' but the argument has type 'double *'}}
74*0a6a1f1dSLionel Sambuc   scanf("%hC", &bad); // expected-warning{{format specifies type 'char *' but the argument has type 'double *'}}
75*0a6a1f1dSLionel Sambuc   scanf("%hs", &bad); // expected-warning{{format specifies type 'char *' but the argument has type 'double *'}}
76*0a6a1f1dSLionel Sambuc   scanf("%hS", &bad); // expected-warning{{format specifies type 'char *' but the argument has type 'double *'}}
77*0a6a1f1dSLionel Sambuc }
78*0a6a1f1dSLionel Sambuc 
z_test(void * p)79*0a6a1f1dSLionel Sambuc void z_test(void *p) {
80*0a6a1f1dSLionel Sambuc   printf("%Z", p);
81*0a6a1f1dSLionel Sambuc   printf("%hZ", p);
82*0a6a1f1dSLionel Sambuc   printf("%lZ", p);
83*0a6a1f1dSLionel Sambuc   printf("%wZ", p);
84*0a6a1f1dSLionel Sambuc   printf("%hhZ", p); // expected-warning{{length modifier 'hh' results in undefined behavior or no effect with 'Z' conversion specifier}}
85*0a6a1f1dSLionel Sambuc   scanf("%Z", p); // expected-warning{{invalid conversion specifier 'Z'}}
86*0a6a1f1dSLionel Sambuc }
87*0a6a1f1dSLionel Sambuc 
88*0a6a1f1dSLionel Sambuc #endif
89