summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp9
-rw-r--r--clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp4
2 files changed, 9 insertions, 4 deletions
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
index 8b0f7ce11d2..af41386d080 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -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);
}
diff --git a/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp b/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
index ce192805dda..2287e48a4fe 100644
--- a/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
+++ b/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
@@ -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() {
OpenPOWER on IntegriCloud