Index: clang-tidy/google/AvoidCStyleCastsCheck.cpp =================================================================== --- clang-tidy/google/AvoidCStyleCastsCheck.cpp +++ clang-tidy/google/AvoidCStyleCastsCheck.cpp @@ -129,14 +129,17 @@ auto ReplaceWithCast = [&](std::string CastText) { const Expr *SubExpr = CastExpr->getSubExprAsWritten()->IgnoreImpCasts(); + auto ReplaceRange = ParenRange; if (!isa(SubExpr)) { CastText.push_back('('); Diag << FixItHint::CreateInsertion( Lexer::getLocForEndOfToken(SubExpr->getLocEnd(), 0, SM, getLangOpts()), ")"); + ReplaceRange = CharSourceRange::getCharRange(CastExpr->getLParenLoc(), + SubExpr->getLocStart()); } - Diag << FixItHint::CreateReplacement(ParenRange, CastText); + Diag << FixItHint::CreateReplacement(ReplaceRange, CastText); }; auto ReplaceWithNamedCast = [&](StringRef CastType) { Diag << CastType; Index: test/clang-tidy/google-readability-casting.cpp =================================================================== --- test/clang-tidy/google-readability-casting.cpp +++ test/clang-tidy/google-readability-casting.cpp @@ -85,6 +85,14 @@ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast/const_cast/reinterpret_cast [ // CHECK-FIXES: b1 = (const int&)b; + b1 = (int) b; + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}} + // CHECK-FIXES: b1 = static_cast(b); + + b1 = (int) b; + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}} + // CHECK-FIXES: b1 = static_cast(b); + Y *pB = (Y*)pX; // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use static_cast/const_cast/reinterpret_cast [ Y &rB = (Y&)*pX;