[Bug c++/49083] New: g++ should error when a variable declared in a condition is hidden by a variable in the immediately contained block
howarth at nitro dot med.uc.edu
gcc-bugzilla@gcc.gnu.org
Fri May 20 16:34:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49083
Summary: g++ should error when a variable declared in a
condition is hidden by a variable in the immediately
contained block
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: howarth@nitro.med.uc.edu
Created attachment 24305
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24305
test case demonstrating the missing error message
Currently g+= 4.6.0 doesn't produce an error for the attached test case,
derived from apt-0.5.4/apt-pkg/deb/deblistparser.cc, despite the fact that a
c++ compiler should error when a variable is declared in a condition that is
hidden by a variable in the immediately contained block. The attached test case
causes the expected compiler errors on HP aCC, AIX xlC, Tru64 cxx and Irix CC.
The g++ compiler only produces a warning if -Wshadow is used. Note that clang
produces the error...
hidden_bug.cc:14:8: error: redefinition of 'I' with a different type
char *I = S;
^
hidden_bug.cc:10:25: note: previous definition is here
for (const char **I = Sections; *I != 0; I++)
^
hidden_bug.cc:18:21: error: assigning to 'const char *' from incompatible type
'char'
*I++ = tolower(*Start);
^ ~~~~~~~~~~~~~~~
hidden_bug.cc:20:22: error: assigning to 'const char *' from incompatible type
'char'
*I++ = '=';
^ ~~~
hidden_bug.cc:22:22: error: assigning to 'const char *' from incompatible type
'char'
*I++ = '=';
^ ~~~
4 errors generated.
More information about the Gcc-bugs
mailing list