v1nh1shungry updated this revision to Diff 486729. v1nh1shungry added a comment.
don't use `auto` Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D141058/new/ https://reviews.llvm.org/D141058 Files: clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-array-subscript-expression.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-int.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-pointer-offset.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-pointer-offset.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-pointer-offset.cpp +++ clang-tools-extra/test/clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-pointer-offset.cpp @@ -18,7 +18,7 @@ // CHECK-NOTES-CXX: static_cast<ptrdiff_t>( ) // CHECK-NOTES-ALL: :[[@LINE-5]]:17: note: perform multiplication in a wider type // CHECK-NOTES-C: (ptrdiff_t) - // CHECK-NOTES-CXX: static_cast<ptrdiff_t>() + // CHECK-NOTES-CXX: static_cast<ptrdiff_t>( ) } char *t1(char *base, int a, int b) { return a * b + base; @@ -35,7 +35,7 @@ // CHECK-NOTES-CXX: static_cast<size_t>( ) // CHECK-NOTES-ALL: :[[@LINE-5]]:17: note: perform multiplication in a wider type // CHECK-NOTES-C: (size_t) - // CHECK-NOTES-CXX: static_cast<size_t>() + // CHECK-NOTES-CXX: static_cast<size_t>( ) } char *t3(char *base, int a, unsigned int b) { Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-int.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-int.cpp +++ clang-tools-extra/test/clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-int.cpp @@ -18,7 +18,7 @@ // CHECK-NOTES-CXX: static_cast<long>( ) // CHECK-NOTES-ALL: :[[@LINE-5]]:10: note: perform multiplication in a wider type // CHECK-NOTES-C: (long) - // CHECK-NOTES-CXX: static_cast<long>() + // CHECK-NOTES-CXX: static_cast<long>( ) } unsigned long t1(int a, int b) { return a * b; @@ -28,7 +28,7 @@ // CHECK-NOTES-CXX: static_cast<unsigned long>( ) // CHECK-NOTES-ALL: :[[@LINE-5]]:10: note: perform multiplication in a wider type // CHECK-NOTES-C: (long) - // CHECK-NOTES-CXX: static_cast<long>() + // CHECK-NOTES-CXX: static_cast<long>( ) } long t2(unsigned int a, int b) { @@ -39,7 +39,7 @@ // CHECK-NOTES-CXX: static_cast<long>( ) // CHECK-NOTES-ALL: :[[@LINE-5]]:10: note: perform multiplication in a wider type // CHECK-NOTES-C: (unsigned long) - // CHECK-NOTES-CXX: static_cast<unsigned long>() + // CHECK-NOTES-CXX: static_cast<unsigned long>( ) } unsigned long t3(unsigned int a, int b) { return a * b; @@ -49,7 +49,7 @@ // CHECK-NOTES-CXX: static_cast<unsigned long>( ) // CHECK-NOTES-ALL: :[[@LINE-5]]:10: note: perform multiplication in a wider type // CHECK-NOTES-C: (unsigned long) - // CHECK-NOTES-CXX: static_cast<unsigned long>() + // CHECK-NOTES-CXX: static_cast<unsigned long>( ) } long t4(int a, unsigned int b) { Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-array-subscript-expression.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-array-subscript-expression.cpp +++ clang-tools-extra/test/clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-array-subscript-expression.cpp @@ -18,7 +18,7 @@ // CHECK-NOTES-CXX: static_cast<ptrdiff_t>( ) // CHECK-NOTES-ALL: :[[@LINE-5]]:16: note: perform multiplication in a wider type // CHECK-NOTES-C: (ptrdiff_t) - // CHECK-NOTES-CXX: static_cast<ptrdiff_t>() + // CHECK-NOTES-CXX: static_cast<ptrdiff_t>( ) } void *t1(char *base, int a, int b) { return &((a * b)[base]); @@ -35,7 +35,7 @@ // CHECK-NOTES-CXX: static_cast<size_t>( ) // CHECK-NOTES-ALL: :[[@LINE-5]]:16: note: perform multiplication in a wider type // CHECK-NOTES-C: (size_t) - // CHECK-NOTES-CXX: static_cast<size_t>() + // CHECK-NOTES-CXX: static_cast<size_t>( ) } char *t3(char *base, int a, unsigned int b) { Index: clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp +++ clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp @@ -9,6 +9,7 @@ #include "ImplicitWideningOfMultiplicationResultCheck.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Lexer.h" using namespace clang::ast_matchers; @@ -95,20 +96,25 @@ "%0 of a multiplication performed in type %1") << Ty << E->getType(); + const SourceManager &SM = Context->getSourceManager(); + const LangOptions &LangOpts = Context->getLangOpts(); + { auto Diag = diag(E->getBeginLoc(), "make conversion explicit to silence this warning", DiagnosticIDs::Note) << E->getSourceRange(); + SourceLocation LocForEndOfToken = + Lexer::getLocForEndOfToken(E->getEndLoc(), 0, SM, LangOpts); if (ShouldUseCXXStaticCast) Diag << FixItHint::CreateInsertion( E->getBeginLoc(), "static_cast<" + Ty.getAsString() + ">(") - << FixItHint::CreateInsertion(E->getEndLoc(), ")"); + << FixItHint::CreateInsertion(LocForEndOfToken, ")"); else Diag << FixItHint::CreateInsertion(E->getBeginLoc(), "(" + Ty.getAsString() + ")(") - << FixItHint::CreateInsertion(E->getEndLoc(), ")"); + << FixItHint::CreateInsertion(LocForEndOfToken, ")"); Diag << includeStddefHeader(E->getBeginLoc()); } @@ -138,7 +144,9 @@ Diag << FixItHint::CreateInsertion(LHS->getBeginLoc(), "static_cast<" + WideExprTy.getAsString() + ">(") - << FixItHint::CreateInsertion(LHS->getEndLoc(), ")"); + << FixItHint::CreateInsertion( + Lexer::getLocForEndOfToken(LHS->getEndLoc(), 0, SM, LangOpts), + ")"); else Diag << FixItHint::CreateInsertion(LHS->getBeginLoc(), "(" + WideExprTy.getAsString() + ")"); @@ -202,21 +210,26 @@ "an implicit widening conversion to type '%1'") << IndexExprType << TyAsString; + const SourceManager &SM = Context->getSourceManager(); + const LangOptions &LangOpts = Context->getLangOpts(); + { auto Diag = diag(IndexExpr->getBeginLoc(), "make conversion explicit to silence this warning", DiagnosticIDs::Note) << IndexExpr->getSourceRange(); + SourceLocation LocForEndOfToken = + Lexer::getLocForEndOfToken(IndexExpr->getEndLoc(), 0, SM, LangOpts); if (ShouldUseCXXStaticCast) Diag << FixItHint::CreateInsertion( IndexExpr->getBeginLoc(), (Twine("static_cast<") + TyAsString + ">(").str()) - << FixItHint::CreateInsertion(IndexExpr->getEndLoc(), ")"); + << FixItHint::CreateInsertion(LocForEndOfToken, ")"); else Diag << FixItHint::CreateInsertion(IndexExpr->getBeginLoc(), (Twine("(") + TyAsString + ")(").str()) - << FixItHint::CreateInsertion(IndexExpr->getEndLoc(), ")"); + << FixItHint::CreateInsertion(LocForEndOfToken, ")"); Diag << includeStddefHeader(IndexExpr->getBeginLoc()); } @@ -230,7 +243,9 @@ Diag << FixItHint::CreateInsertion( LHS->getBeginLoc(), (Twine("static_cast<") + TyAsString + ">(").str()) - << FixItHint::CreateInsertion(LHS->getEndLoc(), ")"); + << FixItHint::CreateInsertion( + Lexer::getLocForEndOfToken(LHS->getEndLoc(), 0, SM, LangOpts), + ")"); else Diag << FixItHint::CreateInsertion(LHS->getBeginLoc(), (Twine("(") + TyAsString + ")").str());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits