| 1 |
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s |
| 2 |
|
| 3 |
int printf(char const *, ...); |
| 4 |
|
| 5 |
#include <stddef.h> |
| 6 |
|
| 7 |
void test(void) { |
| 8 |
// size_t |
| 9 |
printf("%zu", (size_t)0); // no-warning |
| 10 |
printf("%zu", sizeof(int)); // no-warning |
| 11 |
printf("%zu", (size_t)0 + sizeof(int)); // no-warning |
| 12 |
printf("%zu", (double)42); // expected-warning {{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'double'}} |
| 13 |
// intmax_t / uintmax_t |
| 14 |
printf("%jd", (double)42); // expected-warning {{format specifies type 'intmax_t' (aka 'long') but the argument has type 'double'}} |
| 15 |
printf("%ju", (double)42); // expected-warning {{format specifies type 'uintmax_t' (aka 'unsigned long') but the argument has type 'double'}} |
| 16 |
|
| 17 |
// ptrdiff_t |
| 18 |
printf("%td", (double)42); // expected-warning {{format specifies type 'ptrdiff_t' (aka 'long') but the argument has type 'double'}} |
| 19 |
} |
| 20 |
|
| 21 |
void test_writeback(void) { |
| 22 |
printf("%jn", (long*)0); // no-warning |
| 23 |
printf("%jn", (unsigned long*)0); // no-warning |
| 24 |
printf("%jn", (int*)0); // expected-warning{{format specifies type 'intmax_t *' (aka 'long *') but the argument has type 'int *'}} |
| 25 |
|
| 26 |
printf("%zn", (long*)0); // no-warning |
| 27 |
// FIXME: Warn about %zn with non-ssize_t argument. |
| 28 |
|
| 29 |
printf("%tn", (long*)0); // no-warning |
| 30 |
printf("%tn", (unsigned long*)0); // no-warning |
| 31 |
printf("%tn", (int*)0); // expected-warning{{format specifies type 'ptrdiff_t *' (aka 'long *') but the argument has type 'int *'}} |
| 32 |
} |