[PATCH] D54281: [clang-tidy] fix PR39583 - ignoring ParenCast for string-literals in pro-bounds-array-to-pointer-decay
Jonas Toth via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 8 15:44:28 PST 2018
JonasToth created this revision.
JonasToth added reviewers: aaron.ballman, alexfh, hokein.
Herald added subscribers: cfe-commits, kbarton, xazax.hun, nemanjai.
The fix to the issue that `const char* p = ("foo")` is diagnosed as decay
is to ignored the ParenCast.
Resolves PR39583
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D54281
Files:
clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
Index: test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
===================================================================
--- test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
@@ -30,6 +30,7 @@
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 @@
const char *g() {
return "clang"; // OK, decay string literal to pointer
}
+const char *g2() {
+ return ("clang"); // OK, ParenCast hides the literal-pointer decay
+}
void f2(void *const *);
void bug25362() {
Index: clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
===================================================================
--- clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -58,10 +58,11 @@
// 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(ignoringParenCasts(stringLiteral()))))
.bind("cast"),
this);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54281.173241.patch
Type: text/x-patch
Size: 1757 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181108/bf94ed37/attachment.bin>
More information about the cfe-commits
mailing list