Missing Commas in initializer list diagnostic


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




missingCommasDiag.in (150 Bytes)

missingCommasDiag.out (1.13 KB)