Author: rsmith Date: Tue Dec 29 19:06:52 2015 New Revision: 256607 URL: http://llvm.org/viewvc/llvm-project?rev=256607&view=rev Log: Clean up this code, NFC.
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=256607&r1=256606&r2=256607&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Dec 29 19:06:52 2015 @@ -7305,20 +7305,24 @@ void CheckImplicitConversion(Sema &S, Ex } } - // 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); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits