[clang-tools-extra] [Clang-Tidy] Fixed `cppcoreguidelines-init-variables` to handle ObjC for-in loops. (PR #191306)
Dmitrii Kuragin via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 9 17:35:15 PDT 2026
================
@@ -0,0 +1,38 @@
+// 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
+
+// ObjC for-in loop variables should not be flagged, as they are initialized
+// by the loop itself. Previously, the check would incorrectly try to insert
+// '= nullptr' at the wrong source location, corrupting the following statement.
+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];
+ // 'urlString' should NOT be flagged - it has an initializer.
+ (void)urlString;
+ }
+}
----------------
sstepashka wrote:
PTAL.
https://github.com/llvm/llvm-project/pull/191306
More information about the cfe-commits
mailing list