format-strings-int-typedefs.c revision f4f0c6095d1f481b94c6821c65e3bf1c9df42af7
1// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s 2 3int printf(char const *, ...); 4 5void test(void) { 6 printf("%jd", 42.0); // expected-warning {{conversion specifies type 'intmax_t' (aka 'long long')}} 7 printf("%ju", 42.0); // expected-warning {{conversion specifies type 'uintmax_t' (aka 'unsigned long long')}} 8 printf("%zu", 42.0); // expected-warning {{conversion specifies type 'size_t' (aka 'unsigned long')}} 9 printf("%td", 42.0); // expected-warning {{conversion specifies type 'ptrdiff_t' (aka 'int')}} 10 printf("%lc", 42.0); // expected-warning {{conversion specifies type 'wint_t' (aka 'int')}} 11 printf("%ls", 42.0); // expected-warning {{conversion specifies type 'wchar_t *' (aka 'int *')}} 12 printf("%S", 42.0); // expected-warning {{conversion specifies type 'wchar_t *' (aka 'int *')}} 13 printf("%C", 42.0); // expected-warning {{conversion specifies type 'wchar_t' (aka 'int')}} 14 15 16 // typedef size_t et al. to something crazy. 17 typedef void *size_t; 18 typedef void *intmax_t; 19 typedef void *uintmax_t; 20 typedef void *ptrdiff_t; 21 22 // The warning still fires, because it checks the underlying type. 23 printf("%jd", (intmax_t)42); // expected-warning {{conversion specifies type 'intmax_t' (aka 'long long') but the argument has type 'intmax_t' (aka 'void *')}} 24 printf("%ju", (uintmax_t)42); // expected-warning {{conversion specifies type 'uintmax_t' (aka 'unsigned long long') but the argument has type 'uintmax_t' (aka 'void *')}} 25 printf("%zu", (size_t)42); // expected-warning {{conversion specifies type 'size_t' (aka 'unsigned long') but the argument has type 'size_t' (aka 'void *')}} 26 printf("%td", (ptrdiff_t)42); // expected-warning {{conversion specifies type 'ptrdiff_t' (aka 'int') but the argument has type 'ptrdiff_t' (aka 'void *')}} 27} 28