[cfe-dev] Missing Commas in initializer list diagnostic

Zaid Alkhishman via cfe-dev cfe-dev at lists.llvm.org
Mon May 1 21:43:56 PDT 2017


Hi,

This is my first message in this list (plz be gentle).

I've been wanting to contribute to llvm/clang for quite sometime and here
it is.

Subject of the matter today is errors on parsing of initializer list.

When parsing a malformed initializer list, specifically one in which 1 or
more commas are missing, such as this

int a[] = {1 22222 33333, 4};


The errors we get are not exactly close to what the compilee has intended.

test.c:6:18: error: expected '}'
    int a[] = {1 22222 33333, 4};
                 ^
test.c:6:15: note: to match this '{'
    int a[] = {1 22222 33333, 4};

Now the reason why I assume the commas are missing is because it seems to
be the most obvious things that happened here.

So I've went ahead and created a diagnostic which I deemed as more
meaningful and more likely to match what the compilee has intended.

The behaviour is to note the areas where the expected commas would be and
simply suggest inserting them.

Unfortunately the output doesn't quite line up in the email. So I'm
attaching a copy if an input program and what the patched clang outputs as
errors

Regards,

Zaid

zaid.alkhishman at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170502/7464a47e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: missingCommasDiag.in
Type: application/octet-stream
Size: 150 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170502/7464a47e/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: missingCommasDiag.out
Type: application/octet-stream
Size: 1160 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170502/7464a47e/attachment-0001.obj>


More information about the cfe-dev mailing list