Skip to content

Commit 9be33de

Browse files
committed
[clang-tidy]pro-bounds-array-to-pointer-decay ignore predefined expression
cast PredefinedExpr such as `__func__` to const char* should be accpetted. Reviewed By: PiotrZSL Differential Revision: https://reviews.llvm.org/D158244
1 parent 79a8e00 commit 9be33de

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/AST/ParentMapContext.h"
1212
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
#include "clang/ASTMatchers/ASTMatchers.h"
1314

1415
using namespace clang::ast_matchers;
1516

@@ -56,6 +57,7 @@ void ProBoundsArrayToPointerDecayCheck::registerMatchers(MatchFinder *Finder) {
5657
TK_AsIs,
5758
implicitCastExpr(
5859
unless(hasParent(arraySubscriptExpr())),
60+
unless(hasSourceExpression(predefinedExpr())),
5961
unless(hasParentIgnoringImpCasts(explicitCastExpr())),
6062
unless(isInsideOfRangeBeginEndStmt()),
6163
unless(hasSourceExpression(ignoringParens(stringLiteral()))),

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ Changes in existing checks
186186
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check to
187187
ignore delegate constructors.
188188

189+
- Improved :doc `cppcoreguidelines-pro-bounds-array-to-pointer-decay
190+
<clang-tidy/checks/cppcoreguidelines/pro-bounds-array-to-pointer-decay>` check
191+
to ignore predefined expression (e.g., ``__func__``, ...).
192+
189193
- Improved :doc:`cppcoreguidelines-pro-type-member-init
190194
<clang-tidy/checks/cppcoreguidelines/pro-type-member-init>` check to ignore
191195
dependent delegate constructors.

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ const char *g() {
4343
const char *g2() {
4444
return ("clang"); // OK, ParenExpr hides the literal-pointer decay
4545
}
46+
const char *g3() {
47+
return __func__; // OK, don't diagnose PredefinedExpr
48+
}
4649

4750
void f2(void *const *);
4851
void bug25362() {

0 commit comments

Comments
 (0)