[PATCH] D58764: [clang-tidy] ignore predefined expressions in cppcoreguidelines-pro-bounds-array-to-pointer-decay check
Lewis Clark via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 28 02:12:24 PST 2019
lewmpk created this revision.
lewmpk added a reviewer: clang-tools-extra.
lewmpk added projects: clang, clang-tools-extra.
Herald added subscribers: cfe-commits, kbarton, xazax.hun, nemanjai.
Bugzilla: 40852
c++
int main()
{
const char* a = __FILE__;
const char* b = __FUNCTION__;
}
variable `b` is now not marked as an error by `cppcoreguidelines-pro-bounds-array-to-pointer-decay` check
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D58764
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
@@ -44,6 +44,9 @@
return ("clang"); // OK, ParenExpr hides the literal-pointer decay
}
+const char *line = __FILE__; // OK
+const char *func = __FUNCTION__; // OK, predefined value to pointer
+
void f2(void *const *);
void bug25362() {
void *a[2];
Index: clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
===================================================================
--- clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -56,12 +56,14 @@
// 1) just before array subscription
// 2) inside a range-for over an array
// 3) if it converts a string literal to a pointer
+ // 4) if it converts a predefined value to a pointer
Finder->addMatcher(
implicitCastExpr(
unless(hasParent(arraySubscriptExpr())),
unless(hasParentIgnoringImpCasts(explicitCastExpr())),
unless(isInsideOfRangeBeginEndStmt()),
- unless(hasSourceExpression(ignoringParens(stringLiteral()))))
+ unless(hasSourceExpression(ignoringParens(stringLiteral()))),
+ unless(hasSourceExpression(ignoringParens(predefinedExpr()))))
.bind("cast"),
this);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58764.188686.patch
Type: text/x-patch
Size: 1535 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190228/974ec02b/attachment.bin>
More information about the cfe-commits
mailing list