[clang] [Clang][Sema] Fix crash on a string literal following a designated array element (PR #241933)

Akash Manna via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 18 19:40:45 PST 2026


================
@@ -2157,8 +2157,9 @@ void InitListChecker::CheckArrayType(const InitializedEntity &Entity,
     IList->setInit(0, Embed->getDataStringLiteral());
   }
 
-  // Check for the special-case of initializing an array with a string.
-  if (Index < IList->getNumInits()) {
+  // Check for the special-case of initializing an array with a string. After a
+  // designator the string is the initializer of the next element instead.
+  if (Index < IList->getNumInits() && elementIndex.isZero()) {
----------------
akash-manna-sky wrote:

> Is there a reason this isn’t enough? This is essentially what we check for in canInitializeArrayWithEmbedDataString().

That would also skip `char c[] = {"Hello", "excess"};`, which we accept with "excess elements in char array initializer" (array-init.c:162, :174); it would become an int-conversion error. A non-zero `elementIndex` only comes from the designator continuation, so I kept that check.

>Also, while you’re at it, can you merge this if condition with the one of IsStringInit() below using &&; I don’t think there is a good reason to keep them separate

Yes, merged now.

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


More information about the cfe-commits mailing list