17393 – [3.4/4.0 Regression] "unused variable '._0'" warning with -Wall (original) (raw)
Description Timo Erkkilä 2004-09-10 12:22:10 UTC
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ä
Comment 1 Drea Pinski 2004-09-10 15:38:08 UTC
Confirmed, a regression. 3.3.3 just gave:
[pr17393](show%5Fbug.cgi?id=17393 "RESOLVED FIXED - [3.4/4.0 Regression] "unused variable '._0'" warning with -Wall").cc: In function void foo()': [pr17393](show%5Fbug.cgi?id=17393 "RESOLVED FIXED - [3.4/4.0 Regression] "unused variable '._0'" warning with -Wall").cc:5: error: parse error before =' token
Comment 2 Wolfgang Bangerth 2004-09-10 15:56:25 UTC
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.
Comment 3 Gabriel Dos Reis 2004-09-10 16:27:51 UTC
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
Comment 4 Wolfgang Bangerth 2004-09-10 18:00:38 UTC
Well, the error messages changed from
[pr17393](show%5Fbug.cgi?id=17393 "RESOLVED FIXED - [3.4/4.0 Regression] "unused variable '._0'" warning with -Wall").cc: In function void foo()': [pr17393](show%5Fbug.cgi?id=17393 "RESOLVED FIXED - [3.4/4.0 Regression] "unused variable '._0'" warning with -Wall").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.
Comment 7 Mark Mitchell 2004-10-10 21:55:15 UTC
Fixed in GCC 3.4.3.