This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Declaration shadows a parameter?



Having looked more closely at CD2, I am now, too, convinced this is a
bug.  The problem that g++ interprets the declaration of argc in
TempClosure::apply() as being at the outermost block of main()
definition.  If this were the case, than the error message would be
perfectly correct ($3.3.2 [basic.scope.local])

Unfortunately, I do not know enough about g++ internals to fix this
problem, but somebody should probably look into it...

My workaround for this bug is to introduce new scope in apply(), making
the declaration of argc legal:

     virtual void apply() {
	{
	    int argc = 42;
 	    printf("%d\n", argc);
	}
     }

-- Marat

mrs@wrs.com (Mike Stump) writes:
 
| This is a bug, you should only get a warning...

> From: Marat Boshernitsan <maratb@CS.Berkeley.EDU>
> Subject: Declaration shadows a parameter?
> To: egcs-bugs@cygnus.com
> Date: 01 Mar 1998 19:20:02 -0800
> 
> Hi,
> 
> I am having trouble compiling the following piece of code with
> egcs1.0.1.  The error message is 
> 
> closuretest.cc:17: declaration of `argc' shadows a parameter
> 
> but, I cannot find a relevant place in C++ standard that prohibits this.
> 
> Is this a bug in egcs?  Any help would be appreciated. Thanks,
> 
> -- Marat
> 
> P.S. Please CC me on the reply as I only read this mailing list through
> the web site. Thanks.
> 
> 
> 
> 
> #include <stdio.h>
> 
> class Closure {
> public:
>   virtual void apply() = 0;
> };
> 
> void foo(Closure *cl) {
>   cl->apply();
> }
> 
> int main(int argc, char **argv) {
> 
>   class TempClosure : public Closure {
>   public:
>     virtual void apply() {
> 	int argc = 42;
> 	printf("%d\n", argc);
>     }
>   };
> 
>   TempClosure tc;
>   foo(&tc);
> 
>   return 0;
> }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]