blob: 42676e7a4e06e1d03d5237230dbe5a4a3571a2b2 [file] [log] [blame]
Hans Wennborg68f42b92014-09-04 21:39:46 +00001// RUN: %clang_cc1 -fsyntax-only -verify -fms-compatibility -triple=i386-pc-win32 %s
2// RUN: %clang_cc1 -fsyntax-only -verify -fms-compatibility -triple=i386-pc-win32 -Wformat-non-iso -DNON_ISO_WARNING %s
David Majnemer3cba4952013-08-21 21:54:46 +00003
4int printf(const char *format, ...) __attribute__((format(printf, 1, 2)));
Hans Wennborg68f42b92014-09-04 21:39:46 +00005int scanf(const char * restrict, ...) ;
6typedef unsigned short wchar_t;
7
8#ifdef NON_ISO_WARNING
9
10// Split off this test to reduce the warning noise in the rest of the file.
Hans Wennborgc597b4c2014-09-07 03:03:51 +000011void non_iso_warning_test(__int32 i32, __int64 i64, wchar_t c, void *p) {
Hans Wennborg68f42b92014-09-04 21:39:46 +000012 printf("%Id", i32); // expected-warning{{'I' length modifier is not supported by ISO C}}
13 printf("%I32d", i32); // expected-warning{{'I32' length modifier is not supported by ISO C}}
14 printf("%I64d", i64); // expected-warning{{'I64' length modifier is not supported by ISO C}}
15 printf("%wc", c); // expected-warning{{'w' length modifier is not supported by ISO C}}
Hans Wennborgc597b4c2014-09-07 03:03:51 +000016 printf("%Z", p); // expected-warning{{'Z' conversion specifier is not supported by ISO C}}
Hans Wennborg68f42b92014-09-04 21:39:46 +000017}
18
19#else
David Majnemer3cba4952013-08-21 21:54:46 +000020
David Majnemeree7e86c2013-08-22 10:04:41 +000021void signed_test() {
David Majnemer3cba4952013-08-21 21:54:46 +000022 short val = 30;
Hans Wennborg68f42b92014-09-04 21:39:46 +000023 printf("val = %I64d\n", val); // expected-warning{{format specifies type '__int64' (aka 'long long') but the argument has type 'short'}}
David Majnemera39da8e2013-08-22 07:53:21 +000024 long long bigval = 30;
Hans Wennborg68f42b92014-09-04 21:39:46 +000025 printf("val = %I32d\n", bigval); // expected-warning{{format specifies type '__int32' (aka 'int') but the argument has type 'long long'}}
26 printf("val = %Id\n", bigval); // expected-warning{{format specifies type '__int32' (aka 'int') but the argument has type 'long long'}}
David Majnemera39da8e2013-08-22 07:53:21 +000027}
28
David Majnemeree7e86c2013-08-22 10:04:41 +000029void unsigned_test() {
David Majnemera39da8e2013-08-22 07:53:21 +000030 unsigned short val = 30;
Hans Wennborg68f42b92014-09-04 21:39:46 +000031 printf("val = %I64u\n", val); // expected-warning{{format specifies type 'unsigned __int64' (aka 'unsigned long long') but the argument has type 'unsigned short'}}
David Majnemera39da8e2013-08-22 07:53:21 +000032 unsigned long long bigval = 30;
Hans Wennborg68f42b92014-09-04 21:39:46 +000033 printf("val = %I32u\n", bigval); // expected-warning{{format specifies type 'unsigned __int32' (aka 'unsigned int') but the argument has type 'unsigned long long'}}
34 printf("val = %Iu\n", bigval); // expected-warning{{format specifies type 'unsigned __int32' (aka 'unsigned int') but the argument has type 'unsigned long long'}}
David Majnemer3cba4952013-08-21 21:54:46 +000035}
Hans Wennborg68f42b92014-09-04 21:39:46 +000036
37void w_test(wchar_t c, wchar_t *s) {
38 printf("%wc", c);
39 printf("%wC", c);
40 printf("%C", c);
41 printf("%ws", s);
42 printf("%wS", s);
43 printf("%S", s);
44 scanf("%wc", &c);
45 scanf("%wC", &c);
46 scanf("%C", &c);
47 scanf("%ws", s);
48 scanf("%wS", s);
49 scanf("%S", s);
50
51 double bad;
52 printf("%wc", bad); // expected-warning{{format specifies type 'wint_t' (aka 'int') but the argument has type 'double'}}
53 printf("%wC", bad); // expected-warning{{format specifies type 'wchar_t' (aka 'unsigned short') but the argument has type 'double'}}
54 printf("%C", bad); // expected-warning{{format specifies type 'wchar_t' (aka 'unsigned short') but the argument has type 'double'}}
55 printf("%ws", bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double'}}
56 printf("%wS", bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double'}}
57 printf("%S", bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double'}}
58 scanf("%wc", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
59 scanf("%wC", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
60 scanf("%C", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
61 scanf("%ws", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
62 scanf("%wS", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
63 scanf("%S", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
64
65}
66
Hans Wennborg1b231582014-09-04 21:39:52 +000067void h_test(char c, char* s) {
68 double bad;
69 printf("%hc", bad); // expected-warning{{format specifies type 'int' but the argument has type 'double'}}
70 printf("%hC", bad); // expected-warning{{format specifies type 'int' but the argument has type 'double'}}
71 printf("%hs", bad); // expected-warning{{format specifies type 'char *' but the argument has type 'double'}}
72 printf("%hS", bad); // expected-warning{{format specifies type 'char *' but the argument has type 'double'}}
73 scanf("%hc", &bad); // expected-warning{{format specifies type 'char *' but the argument has type 'double *'}}
74 scanf("%hC", &bad); // expected-warning{{format specifies type 'char *' but the argument has type 'double *'}}
75 scanf("%hs", &bad); // expected-warning{{format specifies type 'char *' but the argument has type 'double *'}}
76 scanf("%hS", &bad); // expected-warning{{format specifies type 'char *' but the argument has type 'double *'}}
77}
78
Hans Wennborgc597b4c2014-09-07 03:03:51 +000079void z_test(void *p) {
80 printf("%Z", p);
81 printf("%hZ", p);
82 printf("%lZ", p);
83 printf("%wZ", p);
84 printf("%hhZ", p); // expected-warning{{length modifier 'hh' results in undefined behavior or no effect with 'Z' conversion specifier}}
85 scanf("%Z", p); // expected-warning{{invalid conversion specifier 'Z'}}
86}
87
Hans Wennborg68f42b92014-09-04 21:39:46 +000088#endif