[clang-tools-extra] [Clang-Tidy] Fixed `cppcoreguidelines-init-variables` to handle ObjC for-in loops. (PR #191306)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 17 03:18:03 PDT 2026
================
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables %t -- -- -fno-objc-arc
+
+ at interface NSObject
+ at end
+
+ at interface NSString : NSObject
+ at end
+
+ at interface NSURL : NSObject
+- (NSString *)absoluteString;
+ at end
+
+ at interface NSArray : NSObject
+ at end
+
+void objc_for_in_no_false_positive(NSArray *urls) {
+ for (NSURL *url in urls) {
+ // 'url' should NOT be flagged - it is a for-in loop variable.
+ NSString *urlString = [url absoluteString];
+ }
----------------
vbvictor wrote:
Sorry, I forgot to mention that it should be separate test. It indeed sounded like this should be corrected here.
My initial impression was for these braces to add test-case for catching a FP if somehow `url absoluteString` was treated as declaration and we walked up AST-tree to ObjCForLoopStmt from there.
But that was not the case anyway.
The previous example that you wrote was fine, I'm just not familiar with OBJ-C and misunderstood how it works
https://github.com/llvm/llvm-project/pull/191306
More information about the cfe-commits
mailing list