brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 4b72c3d Raw
47 lines · c
1// RUN: %clang_cc1 -xc %s -verify -DBOOL=_Bool2// RUN: %clang_cc1 -xc++ %s -verify -DBOOL=bool3// RUN: %clang_cc1 -xobjective-c %s -verify -DBOOL=_Bool4// RUN: %clang_cc1 -xc %s -verify -DBOOL=_Bool -Wformat-type-confusion -DTYPE_CONF5// RUN: %clang_cc1 -xc++ %s -verify -DBOOL=bool -Wformat-type-confusion -DTYPE_CONF6 7__attribute__((format(__printf__, 1, 2)))8int p(const char *fmt, ...);9 10BOOL b;11 12#ifdef __OBJC__13@interface NSString14+(NSString *)stringWithFormat:(NSString *)fmt, ...15    __attribute__((format(__NSString__, 1, 2)));16@end17 18#define YES __objc_yes19#define NO __objc_no20#endif21 22int main(void) {23  p("%d", b);24  p("%hd", b);25#ifdef TYPE_CONF26  // expected-warning@-2 {{format specifies type 'short' but the argument has type}}27#endif28  p("%hhd", b);29  p("%u", b);30  p("%hu", b);31#ifdef TYPE_CONF32  // expected-warning@-2 {{format specifies type 'unsigned short' but the argument has type}}33#endif34  p("%hhu", b);35  p("%c", b); // expected-warning {{using '%c' format specifier, but argument has boolean value}}36  p("%lc", b); // expected-warning {{using '%lc' format specifier, but argument has boolean value}}37  p("%c", 1 == 1); // expected-warning {{using '%c' format specifier, but argument has boolean value}}38  p("%f", b); // expected-warning{{format specifies type 'double' but the argument has type}}39  p("%ld", b); // expected-warning{{format specifies type 'long' but the argument has type}}40  p("%lld", b); // expected-warning{{format specifies type 'long long' but the argument has type}}41 42#ifdef __OBJC__43  [NSString stringWithFormat: @"%c", 0]; // probably fine?44  [NSString stringWithFormat: @"%c", NO]; // expected-warning {{using '%c' format specifier, but argument has boolean value}}45#endif46}47