Hans Wennborg | a792aff | 2011-12-07 10:33:11 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s |
| 2 | |
| 3 | int printf(char const *, ...); |
Hans Wennborg | 6fcd932 | 2011-12-10 13:20:11 +0000 | [diff] [blame] | 4 | int scanf(char const *, ...); |
Hans Wennborg | a792aff | 2011-12-07 10:33:11 +0000 | [diff] [blame] | 5 | |
| 6 | void test(void) { |
Ted Kremenek | ce506ae | 2012-01-20 21:52:58 +0000 | [diff] [blame] | 7 | printf("%jd", 42.0); // expected-warning {{format specifies type 'intmax_t' (aka 'long long')}} |
| 8 | printf("%ju", 42.0); // expected-warning {{format specifies type 'uintmax_t' (aka 'unsigned long long')}} |
| 9 | printf("%zu", 42.0); // expected-warning {{format specifies type 'size_t' (aka 'unsigned long')}} |
| 10 | printf("%td", 42.0); // expected-warning {{format specifies type 'ptrdiff_t' (aka 'int')}} |
| 11 | printf("%lc", 42.0); // expected-warning {{format specifies type 'wint_t' (aka 'int')}} |
| 12 | printf("%ls", 42.0); // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}} |
| 13 | printf("%S", 42.0); // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}} |
| 14 | printf("%C", 42.0); // expected-warning {{format specifies type 'wchar_t' (aka 'int')}} |
Hans Wennborg | f4f0c60 | 2011-12-09 12:22:12 +0000 | [diff] [blame] | 15 | |
Ted Kremenek | ce506ae | 2012-01-20 21:52:58 +0000 | [diff] [blame] | 16 | scanf("%jd", 0); // expected-warning {{format specifies type 'intmax_t *' (aka 'long long *')}} |
| 17 | scanf("%ju", 0); // expected-warning {{format specifies type 'uintmax_t *' (aka 'unsigned long long *')}} |
| 18 | scanf("%zu", 0); // expected-warning {{format specifies type 'size_t *' (aka 'unsigned long *')}} |
| 19 | scanf("%td", 0); // expected-warning {{format specifies type 'ptrdiff_t *' (aka 'int *')}} |
| 20 | scanf("%lc", 0); // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}} |
| 21 | scanf("%ls", 0); // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}} |
| 22 | scanf("%S", 0); // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}} |
| 23 | scanf("%C", 0); // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}} |
Hans Wennborg | 6fcd932 | 2011-12-10 13:20:11 +0000 | [diff] [blame] | 24 | |
Hans Wennborg | a792aff | 2011-12-07 10:33:11 +0000 | [diff] [blame] | 25 | |
| 26 | // typedef size_t et al. to something crazy. |
| 27 | typedef void *size_t; |
| 28 | typedef void *intmax_t; |
| 29 | typedef void *uintmax_t; |
| 30 | typedef void *ptrdiff_t; |
| 31 | |
| 32 | // The warning still fires, because it checks the underlying type. |
Ted Kremenek | ce506ae | 2012-01-20 21:52:58 +0000 | [diff] [blame] | 33 | printf("%jd", (intmax_t)42); // expected-warning {{format specifies type 'intmax_t' (aka 'long long') but the argument has type 'intmax_t' (aka 'void *')}} |
| 34 | printf("%ju", (uintmax_t)42); // expected-warning {{format specifies type 'uintmax_t' (aka 'unsigned long long') but the argument has type 'uintmax_t' (aka 'void *')}} |
| 35 | printf("%zu", (size_t)42); // expected-warning {{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'size_t' (aka 'void *')}} |
| 36 | printf("%td", (ptrdiff_t)42); // expected-warning {{format specifies type 'ptrdiff_t' (aka 'int') but the argument has type 'ptrdiff_t' (aka 'void *')}} |
Hans Wennborg | a792aff | 2011-12-07 10:33:11 +0000 | [diff] [blame] | 37 | } |