Hans Wennborg | 68f42b9 | 2014-09-04 21:39:46 +0000 | [diff] [blame^] | 1 | // 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 Majnemer | 3cba495 | 2013-08-21 21:54:46 +0000 | [diff] [blame] | 3 | |
| 4 | int printf(const char *format, ...) __attribute__((format(printf, 1, 2))); |
Hans Wennborg | 68f42b9 | 2014-09-04 21:39:46 +0000 | [diff] [blame^] | 5 | int scanf(const char * restrict, ...) ; |
| 6 | typedef 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. |
| 11 | void non_iso_warning_test(__int32 i32, __int64 i64, wchar_t c) { |
| 12 | 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}} |
| 16 | } |
| 17 | |
| 18 | #else |
David Majnemer | 3cba495 | 2013-08-21 21:54:46 +0000 | [diff] [blame] | 19 | |
David Majnemer | ee7e86c | 2013-08-22 10:04:41 +0000 | [diff] [blame] | 20 | void signed_test() { |
David Majnemer | 3cba495 | 2013-08-21 21:54:46 +0000 | [diff] [blame] | 21 | short val = 30; |
Hans Wennborg | 68f42b9 | 2014-09-04 21:39:46 +0000 | [diff] [blame^] | 22 | printf("val = %I64d\n", val); // expected-warning{{format specifies type '__int64' (aka 'long long') but the argument has type 'short'}} |
David Majnemer | a39da8e | 2013-08-22 07:53:21 +0000 | [diff] [blame] | 23 | long long bigval = 30; |
Hans Wennborg | 68f42b9 | 2014-09-04 21:39:46 +0000 | [diff] [blame^] | 24 | printf("val = %I32d\n", bigval); // expected-warning{{format specifies type '__int32' (aka 'int') but the argument has type 'long long'}} |
| 25 | printf("val = %Id\n", bigval); // expected-warning{{format specifies type '__int32' (aka 'int') but the argument has type 'long long'}} |
David Majnemer | a39da8e | 2013-08-22 07:53:21 +0000 | [diff] [blame] | 26 | } |
| 27 | |
David Majnemer | ee7e86c | 2013-08-22 10:04:41 +0000 | [diff] [blame] | 28 | void unsigned_test() { |
David Majnemer | a39da8e | 2013-08-22 07:53:21 +0000 | [diff] [blame] | 29 | unsigned short val = 30; |
Hans Wennborg | 68f42b9 | 2014-09-04 21:39:46 +0000 | [diff] [blame^] | 30 | printf("val = %I64u\n", val); // expected-warning{{format specifies type 'unsigned __int64' (aka 'unsigned long long') but the argument has type 'unsigned short'}} |
David Majnemer | a39da8e | 2013-08-22 07:53:21 +0000 | [diff] [blame] | 31 | unsigned long long bigval = 30; |
Hans Wennborg | 68f42b9 | 2014-09-04 21:39:46 +0000 | [diff] [blame^] | 32 | printf("val = %I32u\n", bigval); // expected-warning{{format specifies type 'unsigned __int32' (aka 'unsigned int') but the argument has type 'unsigned long long'}} |
| 33 | printf("val = %Iu\n", bigval); // expected-warning{{format specifies type 'unsigned __int32' (aka 'unsigned int') but the argument has type 'unsigned long long'}} |
David Majnemer | 3cba495 | 2013-08-21 21:54:46 +0000 | [diff] [blame] | 34 | } |
Hans Wennborg | 68f42b9 | 2014-09-04 21:39:46 +0000 | [diff] [blame^] | 35 | |
| 36 | void w_test(wchar_t c, wchar_t *s) { |
| 37 | printf("%wc", c); |
| 38 | printf("%wC", c); |
| 39 | printf("%C", c); |
| 40 | printf("%ws", s); |
| 41 | printf("%wS", s); |
| 42 | printf("%S", s); |
| 43 | scanf("%wc", &c); |
| 44 | scanf("%wC", &c); |
| 45 | scanf("%C", &c); |
| 46 | scanf("%ws", s); |
| 47 | scanf("%wS", s); |
| 48 | scanf("%S", s); |
| 49 | |
| 50 | double bad; |
| 51 | printf("%wc", bad); // expected-warning{{format specifies type 'wint_t' (aka 'int') but the argument has type 'double'}} |
| 52 | printf("%wC", bad); // expected-warning{{format specifies type 'wchar_t' (aka 'unsigned short') but the argument has type 'double'}} |
| 53 | printf("%C", bad); // expected-warning{{format specifies type 'wchar_t' (aka 'unsigned short') but the argument has type 'double'}} |
| 54 | printf("%ws", 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("%S", bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double'}} |
| 57 | scanf("%wc", &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("%C", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}} |
| 60 | scanf("%ws", &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("%S", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}} |
| 63 | |
| 64 | } |
| 65 | |
| 66 | #endif |