From c4714b565adc61743ff2b8ee8e9a07a924ef49ab Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 30 Dec 2015 01:06:52 +0000 Subject: [PATCH] Clean up this code, NFC. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256607 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaChecking.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index c4bf82aded..59d51f7e84 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/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(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(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(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(LastA) && (InnerType == Target)) { + if (isa(LastA) && + InnerE->getType()->isBooleanType()) { // Warn on this floating-point to bool conversion DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_floating_point_to_bool); -- 2.40.0