================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits