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