[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


================
@@ -12917,6 +12917,14 @@ bool Sema::CheckForConstantInitializer(Expr *Init, unsigned DiagID) {
   if (Init->isConstantInitializer(Context, /*ForRef=*/false, &Culprit))
     return false;
 
+  // Under ARC, the initializer is wrapped in `ExprWithCleanups` +
+  // `ImplicitCastExpr <ARCReclaimReturnedObject>`. Unwrap both
+  // here so the ObjC-specific path fires under ARC too.
+  Init = Init->IgnoreImpCasts();
----------------
AaronBallman wrote:

Are we sure it's safe to ignore all implicit casts? e.g., non-atomic to atomic, or address space conversions, etc

I'm a bit worried there's a case which *should* be non-constant because of that conversion, but these changes only impact Objective-C literals and I have far less knowledge about those.

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


More information about the cfe-commits mailing list