[clang] [clang-tools-extra] [clang-tidy] Warn about misuse of sizeof operator in loops. (PR #143205)

Ziqing Luo via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 23 04:44:32 PDT 2025


================
@@ -130,6 +140,14 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
                        this);
   }
 
+  if (WarnOnSizeOfInLoopTermination) {
+    Finder->addMatcher(LoopExpr(hasDescendant(binaryOperator(
----------------
ziqingluo-90 wrote:

Since `hasDescendant` is used,  it also matches loop bodies, right? 
Maybe add a test:
```
int A[10];
for(int i = 0; i < sizeof(A); i++) {
         if (x < sizeof(A)) { ... } // Should this be matched? Will this be matched twice?
  }
```
Also please add some tests for nested loops.

https://github.com/llvm/llvm-project/pull/143205


More information about the cfe-commits mailing list