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

Richard Smith richard at metafoo.co.uk
Mon May 13 12:48:17 PDT 2013


On Mon, May 13, 2013 at 9:49 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";
>           ^
>   /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.


Looks good, but how about changing IsStringInit to return a
StringInitFailureKind value? I think the two places which use its return
value rather than just using the same Expr* they passed in are actually
wrong (they pass the IgnoreParens'd version of the return value to
CheckStringInit rather than passing in the original expression, and thus
may fail to update the type on the parens).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130513/158d288b/attachment.html>


More information about the cfe-commits mailing list