format-strings-int-typedefs.c revision a792aff1c7de253b89c473fdb7eef4a5bba83aec
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
11  // typedef size_t et al. to something crazy.
12  typedef void *size_t;
13  typedef void *intmax_t;
14  typedef void *uintmax_t;
15  typedef void *ptrdiff_t;
16
17  // The warning still fires, because it checks the underlying type.
18  printf("%jd", (intmax_t)42); // expected-warning {{conversion specifies type 'intmax_t' (aka 'long long') but the argument has type 'intmax_t' (aka 'void *')}}
19  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 *')}}
20  printf("%zu", (size_t)42); // expected-warning {{conversion specifies type 'size_t' (aka 'unsigned long') but the argument has type 'size_t' (aka 'void *')}}
21  printf("%td", (ptrdiff_t)42); // expected-warning {{conversion specifies type 'ptrdiff_t' (aka 'int') but the argument has type 'ptrdiff_t' (aka 'void *')}}
22}
23