blob: 5058a762183d39ae3e5fb083f3b3790f2c62b16c [file] [log] [blame]
Hans Wennborg29e97cb2011-10-27 08:29:09 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
2
3int printf(char const *, ...);
4
5void test(void) {
6 // size_t
Ted Kremenekce506ae2012-01-20 21:52:58 +00007 printf("%zu", (double)42); // expected-warning {{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'double'}}
Hans Wennborg29e97cb2011-10-27 08:29:09 +00008
9 // intmax_t / uintmax_t
Ted Kremenekce506ae2012-01-20 21:52:58 +000010 printf("%jd", (double)42); // expected-warning {{format specifies type 'intmax_t' (aka 'long') but the argument has type 'double'}}
11 printf("%ju", (double)42); // expected-warning {{format specifies type 'uintmax_t' (aka 'unsigned long') but the argument has type 'double'}}
Hans Wennborg29e97cb2011-10-27 08:29:09 +000012
13 // ptrdiff_t
Ted Kremenekce506ae2012-01-20 21:52:58 +000014 printf("%td", (double)42); // expected-warning {{format specifies type 'ptrdiff_t' (aka 'long') but the argument has type 'double'}}
Hans Wennborg29e97cb2011-10-27 08:29:09 +000015}
Hans Wennborgf7158fa2012-08-07 09:13:19 +000016
17void test_writeback(void) {
18 printf("%jn", (long*)0); // no-warning
19 printf("%jn", (unsigned long*)0); // no-warning
20 printf("%jn", (int*)0); // expected-warning{{format specifies type 'intmax_t *' (aka 'long *') but the argument has type 'int *'}}
21
22 printf("%zn", (long*)0); // no-warning
23 // FIXME: Warn about %zn with non-ssize_t argument.
24
25 printf("%tn", (long*)0); // no-warning
26 printf("%tn", (unsigned long*)0); // no-warning
27 printf("%tn", (int*)0); // expected-warning{{format specifies type 'ptrdiff_t *' (aka 'long *') but the argument has type 'int *'}}
28}