When compiling the test code with "gcc -c -Wshadow", the following warning is emitted: test.cpp: In constructor `A::a1()::B::B()': test.cpp:5: warning: declaration of `this' shadows a parameter test.cpp:3: warning: shadowed declaration is here Note that this warning is not emitted if I don't declare a constructor in the local class (as in A::a2()) I think the warning should always be suppressed if 'this' is involved since it it not a variable as such. I've observed this behaviour in the gcc 3.3 prerelease snapshot from 2003-01-13 as well. I've also observed it on Linux and Solaris. Release: GCC 3.1 How-To-Repeat: cat > test.cpp <<EOF struct A { void a1 () { struct B { B() {} }; } void a2 () { struct B { }; } }; EOF gcc -c -Wshadow test.cpp
Fix: Fixed in GCC 3.3 with: http://gcc.gnu.org/ml/gcc-patches/2003-03/msg00556.html
State-Changed-From-To: open->analyzed State-Changed-Why: Confirmed. Indeed a funny error... This used to not warn until 3.0, but does so with present 3.2, 3.3, and 3.4 CVS, so it's kind of a regression. W:
From: mmitchel@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: c++/9400 Date: 6 Mar 2003 21:10:38 -0000 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2003-03-06 21:10:38 Modified files: gcc/cp : ChangeLog decl.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/warn: Wshadow-2.C Log message: PR c++/9400 * decl.c (pushdecl): Don't check for shadowing of DECL_ARTIFICIAL PARM_DECLs. PR c++/9400 * g++.dg/warn/Wshadow-2.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3239&r2=1.3240 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1014&r2=1.1015 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2473&r2=1.2474 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/warn/Wshadow-2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
From: mmitchel@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: c++/9400 Date: 6 Mar 2003 21:12:14 -0000 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: mmitchel@gcc.gnu.org 2003-03-06 21:12:14 Modified files: gcc/cp : decl.c Added files: gcc/testsuite/g++.dg/warn: Wshadow-2.C Log message: PR c++/9400 * decl.c (pushdecl): Don't check for shadowing of DECL_ARTIFICIAL PARM_DECLs. PR c++/9400 * g++.dg/warn/Wshadow-2.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.965.2.24&r2=1.965.2.25 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/warn/Wshadow-2.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1
From: mmitchel@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: c++/9400 Date: 6 Mar 2003 21:12:52 -0000 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: mmitchel@gcc.gnu.org 2003-03-06 21:12:52 Modified files: gcc/cp : ChangeLog gcc/testsuite : ChangeLog Log message: PR c++/9400 * decl.c (pushdecl): Don't check for shadowing of DECL_ARTIFICIAL PARM_DECLs. PR c++/9400 * g++.dg/warn/Wshadow-2.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.58&r2=1.3076.2.59 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.73&r2=1.2261.2.74
State-Changed-From-To: analyzed->closed State-Changed-Why: Fixed for 3.3.