blob: 341d49c500f43d962fba80a4ca5c7d59a8c01e87 [file] [log] [blame]
Hans Wennborga792aff2011-12-07 10:33:11 +00001// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
2
3int printf(char const *, ...);
Hans Wennborg6fcd9322011-12-10 13:20:11 +00004int scanf(char const *, ...);
Hans Wennborga792aff2011-12-07 10:33:11 +00005
6void test(void) {
Ted Kremenekce506ae2012-01-20 21:52:58 +00007 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')}}
Hans Wennborgf4f0c602011-12-09 12:22:12 +000015
Ted Kremenekce506ae2012-01-20 21:52:58 +000016 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 *')}}
Hans Wennborg6fcd9322011-12-10 13:20:11 +000024
Hans Wennborga792aff2011-12-07 10:33:11 +000025
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.
Ted Kremenekce506ae2012-01-20 21:52:58 +000033 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 *')}}
Hans Wennborga792aff2011-12-07 10:33:11 +000037}