1*011bda80SJordan Rose // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
227541dbeSHans Wennborg
327541dbeSHans Wennborg int printf(char const *, ...);
427541dbeSHans Wennborg
test(void)527541dbeSHans Wennborg void test(void) {
627541dbeSHans Wennborg // size_t
7e7b9d434STed Kremenek printf("%zu", (double)42); // expected-warning {{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'double'}}
827541dbeSHans Wennborg
927541dbeSHans Wennborg // intmax_t / uintmax_t
10e7b9d434STed Kremenek printf("%jd", (double)42); // expected-warning {{format specifies type 'intmax_t' (aka 'long') but the argument has type 'double'}}
11e7b9d434STed Kremenek printf("%ju", (double)42); // expected-warning {{format specifies type 'uintmax_t' (aka 'unsigned long') but the argument has type 'double'}}
1227541dbeSHans Wennborg
1327541dbeSHans Wennborg // ptrdiff_t
14e7b9d434STed Kremenek printf("%td", (double)42); // expected-warning {{format specifies type 'ptrdiff_t' (aka 'long') but the argument has type 'double'}}
1527541dbeSHans Wennborg }
16abc1e22dSHans Wennborg
test_writeback(void)17abc1e22dSHans Wennborg void test_writeback(void) {
18abc1e22dSHans Wennborg printf("%jn", (long*)0); // no-warning
19abc1e22dSHans Wennborg printf("%jn", (unsigned long*)0); // no-warning
20abc1e22dSHans Wennborg printf("%jn", (int*)0); // expected-warning{{format specifies type 'intmax_t *' (aka 'long *') but the argument has type 'int *'}}
21abc1e22dSHans Wennborg
22abc1e22dSHans Wennborg printf("%zn", (long*)0); // no-warning
23abc1e22dSHans Wennborg // FIXME: Warn about %zn with non-ssize_t argument.
24abc1e22dSHans Wennborg
25abc1e22dSHans Wennborg printf("%tn", (long*)0); // no-warning
26abc1e22dSHans Wennborg printf("%tn", (unsigned long*)0); // no-warning
27abc1e22dSHans Wennborg printf("%tn", (int*)0); // expected-warning{{format specifies type 'ptrdiff_t *' (aka 'long *') but the argument has type 'int *'}}
28abc1e22dSHans Wennborg }
29