forked from OSchip/llvm-project
[clang-tidy] Ignore singe bit bitfield -> bool conversion in readability-implicit-bool-conversion
llvm-svn: 343578
This commit is contained in:
parent
271bcb9397
commit
c5016c0a27
|
@ -266,6 +266,7 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
|
|||
|
||||
auto exceptionCases =
|
||||
expr(anyOf(allOf(isMacroExpansion(), unless(isNULLMacroExpansion())),
|
||||
has(ignoringImplicit(memberExpr(hasDeclaration(fieldDecl(hasBitWidth(1)))))),
|
||||
hasParent(explicitCastExpr())));
|
||||
auto implicitCastFromBool = implicitCastExpr(
|
||||
anyOf(hasCastKind(CK_IntegralCast), hasCastKind(CK_IntegralToFloating),
|
||||
|
|
|
@ -66,7 +66,9 @@ example:
|
|||
|
||||
In general, the following conversion types are checked:
|
||||
|
||||
- integer expression/literal to boolean,
|
||||
- integer expression/literal to boolean (conversion from a single bit bitfield
|
||||
to boolean is explicitly allowed, since there's no ambiguity / information
|
||||
loss in this case),
|
||||
|
||||
- floating expression/literal to boolean,
|
||||
|
||||
|
|
|
@ -437,3 +437,24 @@ void useOfUserConversion() {
|
|||
}
|
||||
|
||||
} // namespace ignoreUserDefinedConversionOperator
|
||||
|
||||
namespace ignore_1bit_bitfields {
|
||||
|
||||
struct S {
|
||||
int a;
|
||||
int b : 1;
|
||||
int c : 2;
|
||||
};
|
||||
|
||||
bool f(const S& s) {
|
||||
functionTaking<bool>(s.a);
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int' -> bool
|
||||
// CHECK-FIXES: functionTaking<bool>(s.a != 0);
|
||||
functionTaking<bool>(s.b);
|
||||
// CHECK-FIXES: functionTaking<bool>(s.b);
|
||||
functionTaking<bool>(s.c);
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int' -> bool
|
||||
// CHECK-FIXES: functionTaking<bool>(s.c != 0);
|
||||
}
|
||||
|
||||
} // namespace ignore_1bit_bitfields
|
||||
|
|
Loading…
Reference in New Issue