File tree Expand file tree Collapse file tree 1 file changed +3
-7
lines changed Expand file tree Collapse file tree 1 file changed +3
-7
lines changed Original file line number Diff line number Diff line change 1616
1717using namespace clang ::ast_matchers;
1818
19- namespace {
19+ namespace clang ::tidy::modernize {
20+
21+
2022std::string getText (const clang::Expr *E, const clang::ASTContext &Context) {
2123 auto &SM = Context.getSourceManager ();
2224 auto Range = clang::CharSourceRange::getTokenRange (E->getSourceRange ());
2325 return clang::Lexer::getSourceText (Range, SM, Context.getLangOpts ()).str ();
2426}
25- } // namespace
26-
27- namespace clang ::tidy::modernize {
2827
2928void CleanupStaticCastCheck::registerMatchers (MatchFinder *Finder) {
3029 // Match static_cast expressions not in templates
@@ -42,7 +41,6 @@ void CleanupStaticCastCheck::check(const MatchFinder::MatchResult &Result) {
4241 if (!Cast)
4342 return ;
4443
45- // Get the source expression and its type
4644 const Expr *SubExpr = Cast->getSubExpr ()->IgnoreParenImpCasts ();
4745 QualType SourceType = SubExpr->getType ();
4846 QualType TargetType = Cast->getType ();
@@ -61,10 +59,8 @@ void CleanupStaticCastCheck::check(const MatchFinder::MatchResult &Result) {
6159 " redundant static_cast to the same type %0" ) // Removed single quotes
6260 << TargetType;
6361
64- // Use our helper function to get the source text
6562 std::string ReplacementText = getText (SubExpr, *Result.Context );
6663
67- // Suggest removing the cast
6864 Diag << FixItHint::CreateReplacement (
6965 Cast->getSourceRange (),
7066 ReplacementText);
You can’t perform that action at this time.
0 commit comments