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