GCC-trunk omits the error dignosis about "l_2" in the following error code: $ cat s.c static long a //error static int func_1(void; //error static int func_1(void) { int l_24[4] = {{9L},{(-1L)},{9L},{(-1L)}}; return l_2[2]; //error } int main() { func_1(); return 0; } $ ../gcc-trunk/gcc s.c gcc version 10.0.0 20190913 (experimental) (GCC) target: Ubuntu 4.8.5-4ubuntu8~14.04.2 s.c:1:14: error: expected ‘;’ before ‘static’ static long a ^ ; static int func_1(void; ~~~~~~ s.c:3:13: error: storage class specified for parameter ‘func_1’ static int func_1(void) ^~~~~~ s.c:4:1: error: expected ‘;’, ‘,’ or ‘)’ before ‘{’ token { ^ However, when compiled with clang: $ clang-8.0 -w -ferror-limit=0 s.c s.c:1:14: error: expected ';' after top level declarator static long a ^ ; s.c:2:24: error: expected ')' static int func_1(void; ^ s.c:6:12: error: use of undeclared identifier 'l_2'; did you mean 'l_24'? return l_2[2]; ^~~ l_24 3 errors generated.
Hi, there still exists the above error defect in recent GCC: no error suggestions about ‘l_2’. The reduced code is as follow: static long a //error static int f1(void; //error static int f1(void) { int l_24[0] = {0}; return l_2[0]; //error } $ gcc-trunk -c s.c s.c:1:14: error: expected ‘;’ before ‘static’ 1 | static long a //error | ^ | ; 2 | static int f1(void; //error | ~~~~~~ s.c:3:13: error: storage class specified for parameter ‘f1’ 3 | static int f1(void) | ^~ s.c:4:1: error: expected ‘;’, ‘,’ or ‘)’ before ‘{’ token 4 | { | ^ $ gcc-trunk -version Target: x86_64-pc-linux-gnu Configured with: ../gcc-10-20191124/configure --prefix=/usr/local/gcc-20191124 --enable-checking=release --enable-languages=c,c++ --disable-multilib Thread model: posix Supported LTO compression algorithms: zlib gcc version 10.0.0 20191124 (experimental) (GCC) Best regards
I can confirm GCC doesn't suggest l_24, but I'm not sure it's reasonable to expect it to do so after so many parse errors. If you fix the first two errors then you do get it: 91839.c:6:10: error: ‘l_2’ undeclared (first use in this function); did you mean ‘l_24’? 6 | return l_2[0]; //error | ^~~ | l_24 Your code is ill-formed. GCC tells you it's ill-formed. I don't see a bug here.
(In reply to Jonathan Wakely from comment #2) > I can confirm GCC doesn't suggest l_24, but I'm not sure it's reasonable to > expect it to do so after so many parse errors. > > If you fix the first two errors then you do get it: > > 91839.c:6:10: error: ‘l_2’ undeclared (first use in this function); did you > mean ‘l_24’? > 6 | return l_2[0]; //error > | ^~~ > | l_24 > > > Your code is ill-formed. GCC tells you it's ill-formed. I don't see a bug > here. Hi, thanks for your reply. Error handler should not stop at the first error and report the errors as many as possible. When there are two errors in code, the second error of undeclared ‘b’ is ignored: static int f1(void; //error static int f1(void) { return b; //error } $gcc -c s.c s.c:2:13: error: storage class specified for parameter ‘f1’ 2 | static int f1(void) | ^~ s.c:3:1: error: expected ‘;’, ‘,’ or ‘)’ before ‘{’ token 3 | { | Maybe it could be improved at some extent.
(In reply to tangyixuan from comment #3) > Error handler should not stop at the first error and report the errors as > many as possible. This is not possible in general as the error may cause a cascade of errors that are only "errors" because of the first one. In that case, it is better to stop so that the user knows which error is the actual important one to fix. > Maybe it could be improved at some extent. You are welcome to try: https://gcc.gnu.org/wiki/GettingStarted#Basics:_Contributing_to_GCC_in_10_easy_steps GCC will always need more contributors and you are very welcome to contribute in this area if it is interesting for you. However, existing GCC developers should better spend their time on other more important bugs or features.
There's another bug that this one is reminding me of, but I can't seem to find it right now...