]> git.ipfire.org Git - thirdparty/gcc.git/commit
Fix C/107926: Wrong error message when initializing char array
authorAndrew Pinski <apinski@marvell.com>
Wed, 30 Nov 2022 02:54:57 +0000 (02:54 +0000)
committerAndrew Pinski <apinski@marvell.com>
Sun, 30 Apr 2023 21:48:59 +0000 (21:48 +0000)
commita6b810ae783acf8cec2d2272a46bd6de0976f496
treeaf3d7726b73d91e3425f7a814a7f128f4f4a7b32
parentc53237cefbad0c52799927d6fd99775426a8a92a
Fix C/107926: Wrong error message when initializing char array

The problem here is the code which handles {"a"} is supposed
to handle the case where the is something after the string but
it only handles the case where there is another string so
we go down the other path and error out saying "excess elements
in struct initializer" even though this was a character array.
To fix this, we need to move the ckeck if the initializer is
a string after the check for array and initializer.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Thanks,
Adnrew Pinski

gcc/c/ChangeLog:

PR c/107926
* c-typeck.cc (process_init_element): Move the check
for string cst until after the error message.

gcc/testsuite/ChangeLog:

PR c/107926
* gcc.dg/init-excess-3.c: New test.
gcc/c/c-typeck.cc
gcc/testsuite/gcc.dg/init-excess-3.c [new file with mode: 0644]