Bug 17393 - [3.4/4.0 Regression] "unused variable '._0'" warning with -Wall
Summary: [3.4/4.0 Regression] "unused variable '._0'" warning with -Wall
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.1
: P3 minor
Target Milestone: 3.4.3
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2004-09-10 12:22 UTC by Timo Erkkilä
Modified: 2004-10-10 21:55 UTC (History)
1 user (show)

See Also:
Host: sparc-sun-solaris2.7
Target:
Build:
Known to work: 3.3.3
Known to fail: 3.4.0 4.0.0
Last reconfirmed: 2004-09-17 09:16:54


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 Andrew Pinski 2004-09-10 15:38:08 UTC
Confirmed, a regression. 3.3.3 just gave:
pr17393.cc: In function `void foo()':
pr17393.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.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. 
Comment 5 CVS Commits 2004-10-10 21:49:39 UTC
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

Comment 7 Mark Mitchell 2004-10-10 21:55:15 UTC
Fixed in GCC 3.4.3.