summaryrefslogtreecommitdiff
path: root/test/Sema/format-type-confusion.c
blob: f02bd56676c8fe44754518dfd0f79f28661974e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// RUN: %clang_cc1 -triple x86_64-apple-darwin9.0 -fsyntax-only -verify -Wno-format -Wformat-type-confusion %s

__attribute__((format(__printf__, 1, 2)))
int printf(const char *msg, ...);

#define FMT "%hd %hu %d %u %hhd %hhu %c"

int main() {
  _Bool b = 0;
  printf(FMT,
         b, // expected-warning {{format specifies type 'short' but the argument has type '_Bool'}}
         b, // expected-warning {{format specifies type 'unsigned short' but the argument has type '_Bool'}}
         b, b, b, b, b);

  unsigned char uc = 0;
  printf(FMT,
         uc, // expected-warning {{format specifies type 'short' but the argument has type 'unsigned char'}}
         uc, // expected-warning {{format specifies type 'unsigned short' but the argument has type 'unsigned char'}}
         uc, uc, uc, uc, uc);

  signed char sc = 0;
  printf(FMT,
         sc, // expected-warning {{format specifies type 'short' but the argument has type 'signed char'}}
         sc, // expected-warning {{format specifies type 'unsigned short' but the argument has type 'signed char'}}
         sc, sc, sc, sc, sc);
}