Skip to content

Commit

Permalink
[clang-tidy]pro-bounds-array-to-pointer-decay ignore predefined exp…
Browse files Browse the repository at this point in the history
…ression

cast PredefinedExpr such as `__func__` to const char* should be accpetted.

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D158244
  • Loading branch information
HerrCai0907 committed Aug 19, 2023
1 parent 79a8e00 commit 9be33de
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/ParentMapContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"

using namespace clang::ast_matchers;

Expand Down Expand Up @@ -56,6 +57,7 @@ void ProBoundsArrayToPointerDecayCheck::registerMatchers(MatchFinder *Finder) {
TK_AsIs,
implicitCastExpr(
unless(hasParent(arraySubscriptExpr())),
unless(hasSourceExpression(predefinedExpr())),
unless(hasParentIgnoringImpCasts(explicitCastExpr())),
unless(isInsideOfRangeBeginEndStmt()),
unless(hasSourceExpression(ignoringParens(stringLiteral()))),
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ Changes in existing checks
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check to
ignore delegate constructors.

- Improved :doc `cppcoreguidelines-pro-bounds-array-to-pointer-decay
<clang-tidy/checks/cppcoreguidelines/pro-bounds-array-to-pointer-decay>` check
to ignore predefined expression (e.g., ``__func__``, ...).

- Improved :doc:`cppcoreguidelines-pro-type-member-init
<clang-tidy/checks/cppcoreguidelines/pro-type-member-init>` check to ignore
dependent delegate constructors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const char *g() {
const char *g2() {
return ("clang"); // OK, ParenExpr hides the literal-pointer decay
}
const char *g3() {
return __func__; // OK, don't diagnose PredefinedExpr
}

void f2(void *const *);
void bug25362() {
Expand Down

0 comments on commit 9be33de

Please sign in to comment.