[clang-tools-extra] [clang-tidy] Fix false positive in cert-ctr56-cpp(PointerArithmeticOnPolymorphicObjectCheck) (PR #187452)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 19 00:47:43 PDT 2026
https://github.com/IamYJLee created https://github.com/llvm/llvm-project/pull/187452
## Summary
This change adds `unless(isInstantiationDependent())` to the `ArraySubscript` matcher.
## Motivation
In template code, some array subscript expressions are not fully resolved yet.
Because of this, the matcher may treat them incorrectly and produce false positives.
## Change
This patch skips instantiation-dependent expressions in templates.
It helps the matcher work only on resolved expressions.
Closes https://github.com/llvm/llvm-project/issues/187009.
>From 44205cbf91abd508c2f8737811d96458cb9e5a5c Mon Sep 17 00:00:00 2001
From: LeeYoungJoon <dog3hk.dev at gmail.com>
Date: Thu, 19 Mar 2026 16:39:14 +0900
Subject: [PATCH] [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("+", "-", "+=", "-="),
More information about the cfe-commits
mailing list