[clang] [clang][Sema] Fix ObjC file-scope literal diagnostic under -fobjc-arc (PR #209688)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 15 05:09:51 PDT 2026
================
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx11.0.0 -fobjc-runtime=macosx-11.0.0 -fobjc-constant-literals -fconstant-nsnumber-literals -fconstant-nsarray-literals -fconstant-nsdictionary-literals -verify %s
+// RUN: %clang_cc1 -fsyntax-only -triple arm64-apple-ios15.1.0-simulator -fobjc-runtime=ios-15.1.0 -fobjc-arc -fobjc-constant-literals -fconstant-nsnumber-literals -fconstant-nsarray-literals -fconstant-nsdictionary-literals -verify %s
+
+#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
+typedef unsigned long NSUInteger;
+#else
+typedef unsigned int NSUInteger;
+#endif
+
+ at class NSString;
+
+ at interface NSNumber
++ (NSNumber *)numberWithInt:(int)value;
++ (NSNumber *)numberWithBool:(unsigned char)value;
+ at end
+
+ at interface NSArray
++ (id)arrayWithObjects:(const id[])objects count:(NSUInteger)cnt;
+ at end
+
+ at interface NSDictionary
++ (id)dictionaryWithObjects:(const id[])objects forKeys:(const id[])keys count:(NSUInteger)cnt;
+ at end
+
+// ---- Accepted: NSString literal keys with constant literal values ---------
+
+static NSDictionary *const dASCII = @{@"a" : @1, @"m" : @2, @"z" : @3};
+static NSDictionary *const dEmpty = @{};
----------------
AaronBallman wrote:
Your changes mean we're also going to begin accepting:
```
const NSNumber *i = @2;
```
is that expected and okay?
https://github.com/llvm/llvm-project/pull/209688
More information about the cfe-commits
mailing list