forked from OSchip/llvm-project
parent
bb60f19584
commit
54894fdcc4
|
@ -7305,20 +7305,24 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
|
|||
}
|
||||
}
|
||||
|
||||
// If the target is bool, warn if expr is a function or method call.
|
||||
if (Target->isSpecificBuiltinType(BuiltinType::Bool) &&
|
||||
isa<CallExpr>(E)) {
|
||||
// Detect the case where a call result is converted from floating-point to
|
||||
// to bool, and the final argument to the call is converted from bool, to
|
||||
// discover this typo:
|
||||
//
|
||||
// bool b = fabs(x < 1.0); // should be "bool b = fabs(x) < 1.0;"
|
||||
//
|
||||
// FIXME: This is an incredibly special case; is there some more general
|
||||
// way to detect this class of misplaced-parentheses bug?
|
||||
if (Target->isBooleanType() && isa<CallExpr>(E)) {
|
||||
// Check last argument of function call to see if it is an
|
||||
// implicit cast from a type matching the type the result
|
||||
// is being cast to.
|
||||
CallExpr *CEx = cast<CallExpr>(E);
|
||||
unsigned NumArgs = CEx->getNumArgs();
|
||||
if (NumArgs > 0) {
|
||||
if (unsigned NumArgs = CEx->getNumArgs()) {
|
||||
Expr *LastA = CEx->getArg(NumArgs - 1);
|
||||
Expr *InnerE = LastA->IgnoreParenImpCasts();
|
||||
const Type *InnerType =
|
||||
S.Context.getCanonicalType(InnerE->getType()).getTypePtr();
|
||||
if (isa<ImplicitCastExpr>(LastA) && (InnerType == Target)) {
|
||||
if (isa<ImplicitCastExpr>(LastA) &&
|
||||
InnerE->getType()->isBooleanType()) {
|
||||
// Warn on this floating-point to bool conversion
|
||||
DiagnoseImpCast(S, E, T, CC,
|
||||
diag::warn_impcast_floating_point_to_bool);
|
||||
|
|
Loading…
Reference in New Issue