Hello, I found this minor bug that produces a wrong warning message just recently. The following erroneous source code, when compiled with -Wall struct A { }; void foo() { A& = a; } results in this output: g++ -Wall foo.cc foo.cc: In function `void foo()': foo.cc:5: error: abstract declarator `A&' used as declaration foo.cc:5: error: `a' undeclared (first use this function) foo.cc:5: error: (Each undeclared identifier is reported only once for each function it appears in.) foo.cc:5: warning: unused variable '._0' Here are the configuration options of the compiler: Reading specs from /share/local/lang/gcc341-sol7/bin/../lib/gcc/sparc-sun-solaris2.7/3.4.1/specs Configured with: ../../gcc-3.4.1/configure --prefix=/opt/local/lang/gcc341-sol7 --enable-shared --enable-cpp --disable-threads --with-gnu-ld --with-ld=/opt/local/lang/gcc341-sol7/bin/ld --with-gnu-as --with-as=/opt/local/lang/gcc341-sol7/bin/as --with-cpu=supersparc --disable-nls --disable-multilib --enable-c99 --enable-concept-checks --with-dwarf2 --enable-languages=c,c++ Thread model: single gcc version 3.4.1 Yours, Timo Erkkilä
Confirmed, a regression. 3.3.3 just gave: pr17393.cc: In function `void foo()': pr17393.cc:5: error: parse error before `=' token
That's related to the new parser. The problem with the warning is that gcc tries to make some sense out of your wrong code and introduces an unnamed variable for something it tried on the broken declaration, and this unnamed variable is later found to be unused. I wouldn't rate this as a regression: we give a sensible error message, and this is a follow-up error. It could be rated as error-recovery. If it were just me, I would close this PR as WONTFIX, but I leave this to others. W.
Subject: Re: [3.4/4.0 Regression] "unused variable '._0'" warning with -Wall "bangerth at dealii dot org" <gcc-bugzilla@gcc.gnu.org> writes: | That's related to the new parser. The problem with the warning is | that gcc tries to make some sense out of your wrong code and | introduces an unnamed variable for something it tried on the broken | declaration, and this unnamed variable is later found to be unused. Your analyzis is absolutly right. However, that is a regression in the quality of diagnostic we used to give. -- Gaby
Well, the error messages changed from pr17393.cc: In function `void foo()': pr17393.cc:5: error: parse error before `=' token to foo.cc:5: error: abstract declarator `A&' used as declaration foo.cc:5: error: `a' undeclared (first use this function) foo.cc:5: error: (Each undeclared identifier is reported only once for each function it appears in.) I don't know which is better or worse. The warning about the unused variable is just a follow-up that most people will very likely ignore when they see the first error. W.
Subject: Bug 17393 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2004-10-10 21:49:27 Modified files: gcc/cp : ChangeLog decl.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/parse: error21.C Log message: PR c++/17393 * decl.c (grokdeclarator): Robustify error-recovery on invalid declarations. PR c++/17393 * g++.dg/parse/error21.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4418&r2=1.4419 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1312&r2=1.1313 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4430&r2=1.4431 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/error21.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 17393 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: mmitchel@gcc.gnu.org 2004-10-10 21:55:02 Modified files: gcc/cp : ChangeLog decl.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/parse: error21.C Log message: PR c++/17393 * decl.c (grokdeclarator): Robustify error-recovery on invalid declarations. PR c++/17393 * g++.dg/parse/error21.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.166&r2=1.3892.2.167 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.1174.2.25&r2=1.1174.2.26 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.283&r2=1.3389.2.284 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/error21.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
Fixed in GCC 3.4.3.