Author: Congcong Cai Date: 2023-08-19T08:13:00+08:00 New Revision: 9be33de4f39713c2deb7cc262b4dd4e50dc8349d
URL: https://github.com/llvm/llvm-project/commit/9be33de4f39713c2deb7cc262b4dd4e50dc8349d DIFF: https://github.com/llvm/llvm-project/commit/9be33de4f39713c2deb7cc262b4dd4e50dc8349d.diff LOG: [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 Added: Modified: 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 Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp index c210cb67e4f6b1..6f67ab955baa34 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp +++ b/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 @@ void ProBoundsArrayToPointerDecayCheck::registerMatchers(MatchFinder *Finder) { TK_AsIs, implicitCastExpr( unless(hasParent(arraySubscriptExpr())), + unless(hasSourceExpression(predefinedExpr())), unless(hasParentIgnoringImpCasts(explicitCastExpr())), unless(isInsideOfRangeBeginEndStmt()), unless(hasSourceExpression(ignoringParens(stringLiteral()))), diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index a80473f09464fe..5cf09bd26fab82 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -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. diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp index d41f54b4e77f2a..0bd058caf74ffe 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp @@ -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() { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits