forked from OSchip/llvm-project
[Diagnostics] Use Expr::isKnownToHaveBooleanValue() to check bitwise negation of bool in languages without a bool type
Thanks for this advice, Richard Trieu! llvm-svn: 373817
This commit is contained in:
parent
482f4d9aa9
commit
559265c8da
|
@ -13479,7 +13479,7 @@ ExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc,
|
||||||
// C99 does not support '~' for complex conjugation.
|
// C99 does not support '~' for complex conjugation.
|
||||||
Diag(OpLoc, diag::ext_integer_complement_complex)
|
Diag(OpLoc, diag::ext_integer_complement_complex)
|
||||||
<< resultType << Input.get()->getSourceRange();
|
<< resultType << Input.get()->getSourceRange();
|
||||||
else if (Input.get()->IgnoreParenImpCasts()->getType()->isBooleanType())
|
else if (Input.get()->isKnownToHaveBooleanValue())
|
||||||
Diag(OpLoc, diag::warn_bitwise_negation_bool)
|
Diag(OpLoc, diag::warn_bitwise_negation_bool)
|
||||||
<< FixItHint::CreateReplacement(OpLoc, "!");
|
<< FixItHint::CreateReplacement(OpLoc, "!");
|
||||||
else if (resultType->hasIntegerRepresentation())
|
else if (resultType->hasIntegerRepresentation())
|
||||||
|
|
|
@ -19,4 +19,6 @@ void test(boolean b, int i) {
|
||||||
b = ~i;
|
b = ~i;
|
||||||
i = ~b; // expected-warning {{bitwise negation of a boolean expression; did you mean logical negation?}}
|
i = ~b; // expected-warning {{bitwise negation of a boolean expression; did you mean logical negation?}}
|
||||||
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
|
||||||
|
b = ~(i > 4); // expected-warning {{bitwise negation of a boolean expression; did you mean logical negation?}}
|
||||||
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue