diff options
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index c4bf82aded6..59d51f7e84c 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -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); |

