[Patch] Better diagnostics for string initialization (and fix for C11)

David Blaikie dblaikie at gmail.com
Tue May 14 08:12:53 PDT 2013


On May 13, 2013 9:59 AM, "Hans Wennborg" <hans at chromium.org> wrote:
>
> Hi all,
>
> The attached patch fixes Clang's diagnostics concerning string
> initialization. Where it would previously say:
>
>   /tmp/a.c:3:9: error: array initializer must be an initializer list
>   wchar_t s[] = "Hi";
>           ^
>   /tmp/a.c:4:6: error: array initializer must be an initializer list
> or string literal
>   char t[] = L"Hi";
>        ^
>
> It will now say
>
>   /tmp/a.c:3:9: error: initializing wide char array with non-wide string
literal
>   wchar_t s[] = "Hi";

Worth it/possible/convenient to go one step further and provide a fixit to
insert the 'L' and appropriately recover? I suppose that's probably
orthogonal to your patch, though.

>           ^
>   /tmp/a.c:4:6: error: initializing char array with wide string literal
>   char t[] = L"Hi";
>        ^
>
> As a bonus, it also fixes the fact that Clang would previously reject
> this valid C11 code:
>
>   char16_t s[] = u"hi";
>   char32_t t[] = U"hi";1
>
> because it would only recognize the built-in types for char16_t and
> char32_t, which do not exist in C.
>
> Please take a look.
>
> Thanks,
> Hans
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130514/e78444cb/attachment.html>


More information about the cfe-commits mailing list