c++/7387: gcc 3.1 accepts if (int x = f()) {int x;}
dobrynin@bigfoot.com
dobrynin@bigfoot.com
Tue Jul 23 11:56:00 GMT 2002
>Number: 7387
>Category: c++
>Synopsis: gcc 3.1 accepts if (int x = f()) {int x;}
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: accepts-illegal
>Submitter-Id: net
>Arrival-Date: Tue Jul 23 11:56:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Nickolai Dobrynin, University of WI-Milwaukee
>Release: gcc version 3.1.1 20020714 (prerelease)
>Organization:
>Environment:
1) Cygwin, Windows 2000, Pentium III:
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.1.1/specs
Configured with: /netrel/src/gcc-3.1.1-3/configure --enable-languages=c,c++,f77,
java --enable-libgcj --enable-threads=posix --with-system-zlib --enable-nls --wi
thout-included-gettext --disable-shared --enable-interpreter --disable-sjlj-exce
ptions --disable-version-specific-runtime-libs --build=i686-pc-linux --host=i686
-pc-cygwin --target=i686-pc-cygwin --enable-haifa --prefix=/usr --exec-prefix=/u
sr --sysconfdir=/etc --libdir=/usr/lib --includedir=/nonexistent/include --libex
ecdir=/usr/sbin
Thread model: posix
gcc version 3.1.1 20020714 (prerelease)
******************************
2) Also Mingw on Windows 2000, Pentium III:
Reading specs from C:/progra~1/gcc3.1/bin/../lib/gcc-lib/mingw32/3.1/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=
mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable
-languages=f77,c++,objc,ada --disable-win32-registry --disable-shared
Thread model: win32
gcc version 3.1
>Description:
In the following code,
if (int x = f()) {
int x; //erroneously accepted
}
"int x = f()" introduces a new variable 'x'. According to
[6.4], "if the name is re-declared in the outermost block
of a substatement controlled by the condition, the
declaration that re-declares the name is ill-formed".
$ g++ -Wall 6_4bug.cpp
gccbug.cpp: In function `int main()':
gccbug.cpp:6: warning: unused variable `int x'
gccbug.cpp:9: warning: unused variable `int x'
gccbug.cpp:5: warning: unused variable `int x'
>How-To-Repeat:
int f();
int main()
{
if (int x = f()) {
int x; // ill-formed, redeclaration of 'x'
}
else {
int x; // ill-formed, redeclaration of 'x'
}
return 0;
}
int f() {return 0;}
// Compile with g++ -Wall 6_4bug.cpp
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="6_4bug.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="6_4bug.cpp"
aW50IGYoKTsKCmludCBtYWluKCkKewogICBpZiAoaW50IHggPSBmKCkpIHsKICAgICBpbnQgeDsg
ICAvLyBpbGwtZm9ybWVkLCByZWRlY2xhcmF0aW9uIG9mICd4JwogICB9CiAgIGVsc2UgewogICAg
IGludCB4OyAgIC8vIGlsbC1mb3JtZWQsIHJlZGVjbGFyYXRpb24gb2YgJ3gnCiAgIH0KCiAgIHJl
dHVybiAwOwp9CgoKaW50IGYoKSB7cmV0dXJuIDA7fQo=
More information about the Gcc-prs
mailing list