[clang] [ObjC] Emit number, array, and dictionary literals as constants (PR #185130)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 6 16:55:11 PST 2026
================
@@ -12861,6 +12862,52 @@ bool Sema::CheckForConstantInitializer(Expr *Init, unsigned DiagID) {
const Expr *Culprit;
if (Init->isConstantInitializer(Context, false, &Culprit))
return false;
+
+ // Emit ObjC-specific diagnostics for non-constant literals at file scope.
+ if (getLangOpts().ObjCConstantLiterals && isa<ObjCObjectLiteral>(Culprit)) {
+
+ // For collection literals iterate the elements to highlight which one is
+ // the offender.
+ if (auto ALE = dyn_cast<ObjCArrayLiteral>(Init)) {
+ for (size_t I = 0, N = ALE->getNumElements(); I != N; ++I) {
----------------
ojhunt wrote:
Can we add an `elements()` iterator to `ObjCArrayLiteral`? I guess it doesn't need to be in this PR though
https://github.com/llvm/llvm-project/pull/185130
More information about the cfe-commits
mailing list