[PATCH] D158244: [clang-tidy]`pro-bounds-array-to-pointer-decay` ignore predefined expression

Congcong Cai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 18 17:13:22 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG9be33de4f397: [clang-tidy]`pro-bounds-array-to-pointer-decay` ignore predefined expression (authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158244/new/

https://reviews.llvm.org/D158244

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
@@ -43,6 +43,9 @@
 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() {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -186,6 +186,10 @@
   <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.
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -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;
 
@@ -56,6 +57,7 @@
           TK_AsIs,
           implicitCastExpr(
               unless(hasParent(arraySubscriptExpr())),
+              unless(hasSourceExpression(predefinedExpr())),
               unless(hasParentIgnoringImpCasts(explicitCastExpr())),
               unless(isInsideOfRangeBeginEndStmt()),
               unless(hasSourceExpression(ignoringParens(stringLiteral()))),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158244.551677.patch
Type: text/x-patch
Size: 2297 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230819/f5e483e2/attachment-0001.bin>


More information about the cfe-commits mailing list