comparison clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp @ 173:0572611fdcc8 llvm10 llvm12

reorgnization done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 11:55:54 +0900
parents 1d019706d866
children 2e18cbf3894f
comparison
equal deleted inserted replaced
172:9fbae9c8bf63 173:0572611fdcc8
47 return InnerMatcher.matches(*E, Finder, Builder); 47 return InnerMatcher.matches(*E, Finder, Builder);
48 } 48 }
49 } // namespace 49 } // namespace
50 50
51 void ProBoundsArrayToPointerDecayCheck::registerMatchers(MatchFinder *Finder) { 51 void ProBoundsArrayToPointerDecayCheck::registerMatchers(MatchFinder *Finder) {
52 if (!getLangOpts().CPlusPlus)
53 return;
54
55 // The only allowed array to pointer decay 52 // The only allowed array to pointer decay
56 // 1) just before array subscription 53 // 1) just before array subscription
57 // 2) inside a range-for over an array 54 // 2) inside a range-for over an array
58 // 3) if it converts a string literal to a pointer 55 // 3) if it converts a string literal to a pointer
59 Finder->addMatcher( 56 Finder->addMatcher(
60 implicitCastExpr( 57 traverse(ast_type_traits::TK_AsIs,
61 unless(hasParent(arraySubscriptExpr())), 58 implicitCastExpr(
62 unless(hasParentIgnoringImpCasts(explicitCastExpr())), 59 unless(hasParent(arraySubscriptExpr())),
63 unless(isInsideOfRangeBeginEndStmt()), 60 unless(hasParentIgnoringImpCasts(explicitCastExpr())),
64 unless(hasSourceExpression(ignoringParens(stringLiteral())))) 61 unless(isInsideOfRangeBeginEndStmt()),
65 .bind("cast"), 62 unless(hasSourceExpression(ignoringParens(stringLiteral()))))
63 .bind("cast")),
66 this); 64 this);
67 } 65 }
68 66
69 void ProBoundsArrayToPointerDecayCheck::check( 67 void ProBoundsArrayToPointerDecayCheck::check(
70 const MatchFinder::MatchResult &Result) { 68 const MatchFinder::MatchResult &Result) {