Skip to content

Commit

Permalink
[clang-tidy] fix PR39583 - ignoring ParenCast for string-literals in …
Browse files Browse the repository at this point in the history
…pro-bounds-array-to-pointer-decay

Summary:
The fix to the issue that `const char* p = ("foo")` is diagnosed as decay
is to ignored the ParenCast.
Resolves PR39583

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits

Differential Revision: https://reviews.llvm.org/D54281

llvm-svn: 346555
  • Loading branch information
JonasToth committed Nov 9, 2018
1 parent 295aa09 commit ef67ce0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Expand Up @@ -58,10 +58,11 @@ void ProBoundsArrayToPointerDecayCheck::registerMatchers(MatchFinder *Finder) {
// 2) inside a range-for over an array
// 3) if it converts a string literal to a pointer
Finder->addMatcher(
implicitCastExpr(unless(hasParent(arraySubscriptExpr())),
unless(hasParentIgnoringImpCasts(explicitCastExpr())),
unless(isInsideOfRangeBeginEndStmt()),
unless(hasSourceExpression(stringLiteral())))
implicitCastExpr(
unless(hasParent(arraySubscriptExpr())),
unless(hasParentIgnoringImpCasts(explicitCastExpr())),
unless(isInsideOfRangeBeginEndStmt()),
unless(hasSourceExpression(ignoringParens(stringLiteral()))))
.bind("cast"),
this);
}
Expand Down
Expand Up @@ -30,6 +30,7 @@ void f() {
arrayviewfun(av); // OK

int i = a[0]; // OK
int j = a[(1 + 2)];// OK
pointerfun(&a[0]); // OK

for (auto &e : a) // OK, iteration internally decays array to pointer
Expand All @@ -39,6 +40,9 @@ void f() {
const char *g() {
return "clang"; // OK, decay string literal to pointer
}
const char *g2() {
return ("clang"); // OK, ParenExpr hides the literal-pointer decay
}

void f2(void *const *);
void bug25362() {
Expand Down

0 comments on commit ef67ce0

Please sign in to comment.