Index: clang/lib/AST/FormatString.cpp =================================================================== --- clang/lib/AST/FormatString.cpp +++ clang/lib/AST/FormatString.cpp @@ -360,7 +360,9 @@ case BuiltinType::UChar: case BuiltinType::Char_U: return Match; - } + case BuiltinType::Bool: + return NoMatchPedantic; + } return NoMatch; } @@ -390,6 +392,11 @@ return NoMatchPedantic; return T == C.UnsignedCharTy || T == C.SignedCharTy ? Match : NoMatch; + case BuiltinType::Bool: + if (T == C.UnsignedShortTy || T == C.ShortTy || + T == C.UnsignedCharTy || T == C.SignedCharTy) + return NoMatchPedantic; + return NoMatch; case BuiltinType::Short: return T == C.UnsignedShortTy ? Match : NoMatch; case BuiltinType::UShort: Index: clang/test/Sema/format-bool.c =================================================================== --- /dev/null +++ clang/test/Sema/format-bool.c @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -xc %s -verify -DBOOL=_Bool +// RUN: %clang_cc1 -xc++ %s -verify -DBOOL=bool +// RUN: %clang_cc1 -xc %s -verify -DBOOL=_Bool -Wformat-pedantic -DPEDANTIC +// RUN: %clang_cc1 -xc++ %s -verify -DBOOL=bool -Wformat-pedantic -DPEDANTIC + +__attribute__((format(__printf__, 1, 2))) +int p(const char *fmt, ...); + +BOOL b; + +int main() { + p("%d", b); + p("%hd", b); + p("%hhd", b); +#ifdef PEDANTIC + // expected-warning@-3 {{format specifies type 'short' but the argument has type}} + // expected-warning@-3 {{format specifies type 'char' but the argument has type}} +#endif + p("%u", b); + p("%hu", b); + p("%hhu", b); +#ifdef PEDANTIC + // expected-warning@-3 {{format specifies type 'unsigned short' but the argument has type}} + // expected-warning@-3 {{format specifies type 'unsigned char' but the argument has type}} +#endif + p("%c", b); + p("%f", b); // expected-warning{{format specifies type 'double' but the argument has type}} + p("%ld", b); // expected-warning{{format specifies type 'long' but the argument has type}} +}