[clang-tidy] fix PR39583 - ignoring ParenCast for string-literals in 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
This commit is contained in:
Jonas Toth 2018-11-09 20:57:28 +00:00
parent 295aa09dd2
commit ef67ce0f6f
2 changed files with 9 additions and 4 deletions

View File

@ -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())),
implicitCastExpr(
unless(hasParent(arraySubscriptExpr())),
unless(hasParentIgnoringImpCasts(explicitCastExpr())),
unless(isInsideOfRangeBeginEndStmt()),
unless(hasSourceExpression(stringLiteral())))
unless(hasSourceExpression(ignoringParens(stringLiteral()))))
.bind("cast"),
this);
}

View File

@ -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
@ -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() {