https://github.com/IamYJLee updated https://github.com/llvm/llvm-project/pull/187452
>From d949e0ed4d118eeff746cfd33ef7fdaa2090a0cd Mon Sep 17 00:00:00 2001 From: LeeYoungJoon <[email protected]> Date: Thu, 19 Mar 2026 16:39:14 +0900 Subject: [PATCH 1/4] [clang-tidy] Fix false positive in cert-ctr56-cpp(PointerArithmeticOnPolymorphicObjectCheck) - Add 'unless(isInstantiationDependent())' to the ArraySubscript matcher to skip expressions that are not yet resolved in templates. --- .../bugprone/PointerArithmeticOnPolymorphicObjectCheck.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/PointerArithmeticOnPolymorphicObjectCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/PointerArithmeticOnPolymorphicObjectCheck.cpp index c21abad947912..ac886143b8d98 100644 --- a/clang-tools-extra/clang-tidy/bugprone/PointerArithmeticOnPolymorphicObjectCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/PointerArithmeticOnPolymorphicObjectCheck.cpp @@ -53,7 +53,8 @@ void PointerArithmeticOnPolymorphicObjectCheck::registerMatchers( ? PointerExprWithVirtualMethod : PolymorphicPointerExpr; - const auto ArraySubscript = arraySubscriptExpr(hasBase(SelectedPointerExpr)); + const auto ArraySubscript = expr(arraySubscriptExpr(hasBase(SelectedPointerExpr)), + unless(isInstantiationDependent())); const auto BinaryOperators = binaryOperator(hasAnyOperatorName("+", "-", "+=", "-="), >From bb0c5a3db1905f0624d81719a7b20e6a446ca143 Mon Sep 17 00:00:00 2001 From: LeeYoungJoon <[email protected]> Date: Thu, 19 Mar 2026 16:58:18 +0900 Subject: [PATCH 2/4] [clang-tidy] fix clang-format issues --- .../bugprone/PointerArithmeticOnPolymorphicObjectCheck.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/PointerArithmeticOnPolymorphicObjectCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/PointerArithmeticOnPolymorphicObjectCheck.cpp index ac886143b8d98..ef5fee9f3d2c3 100644 --- a/clang-tools-extra/clang-tidy/bugprone/PointerArithmeticOnPolymorphicObjectCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/PointerArithmeticOnPolymorphicObjectCheck.cpp @@ -53,8 +53,9 @@ void PointerArithmeticOnPolymorphicObjectCheck::registerMatchers( ? PointerExprWithVirtualMethod : PolymorphicPointerExpr; - const auto ArraySubscript = expr(arraySubscriptExpr(hasBase(SelectedPointerExpr)), - unless(isInstantiationDependent())); + const auto ArraySubscript = + expr(arraySubscriptExpr(hasBase(SelectedPointerExpr)), + unless(isInstantiationDependent())); const auto BinaryOperators = binaryOperator(hasAnyOperatorName("+", "-", "+=", "-="), >From 1c5c736e59c20d8e8e8e1ea125c380ec70017b54 Mon Sep 17 00:00:00 2001 From: LeeYoungJoon <[email protected]> Date: Mon, 23 Mar 2026 11:21:55 +0900 Subject: [PATCH 3/4] [clang-tidy] Add test case and mock header for std::map --- .../pointer-arithmetic-on-polymorphic-object-all.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/pointer-arithmetic-on-polymorphic-object-all.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/pointer-arithmetic-on-polymorphic-object-all.cpp index caf24f79ad2d8..f8163a2fd3fb8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/pointer-arithmetic-on-polymorphic-object-all.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/pointer-arithmetic-on-polymorphic-object-all.cpp @@ -1,5 +1,7 @@ // RUN: %check_clang_tidy %s bugprone-pointer-arithmetic-on-polymorphic-object %t -- +#include <map> + class Base { public: virtual ~Base() {} @@ -138,3 +140,13 @@ void typeAliases(BaseAlias *b, DerivedAlias *d, FinalDerivedAlias *fd, fdp += 1; // no-warning } + +template <typename T> +struct TemplateHolder : Base { + std::map<Base *, T> _map; + void test() { + auto &x = _map[this]; + // no-warning + (void)x; + } +}; >From 5251d5bbaa4482af007bdd0cb2c04805bba34c75 Mon Sep 17 00:00:00 2001 From: LeeYoungJoon <[email protected]> Date: Mon, 23 Mar 2026 11:39:30 +0900 Subject: [PATCH 4/4] [clang-tidy] Add ReleaseNotes.rst --- clang-tools-extra/docs/ReleaseNotes.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index a346fee4ea33c..343f216ff13b3 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -223,6 +223,10 @@ Changes in existing checks <clang-tidy/checks/bugprone/macro-parentheses>` check by printing the macro definition in the warning message if the macro is defined on command line. +- Improved :doc:`bugprone-pointer-arithmetic-on-polymorphic-object + <clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object>` check + by fixing a false positive when ``operator[]`` is used in a dependent context. + - Improved :doc:`bugprone-std-namespace-modification <clang-tidy/checks/bugprone/std-namespace-modification>` check by fixing false positives when extending the standard library with a specialization of _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
