This is the mail archive of the gcc@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]
Other format: [Raw text]

Re: shadowed "for" scope variables not throwing up a warning (gcc 3.1.1/cygwin)


I just tried the -Wshadow option and it seems to be a bit of overkill for
the problem I'm describing.

The std boost libs don't even compile with this option enabled so the option
is pretty much useless at this time.

My problem is more to do with the iso-compliancy of gcc's current
implementation of scopes for the "for" statement.  I was always under the
impression that the variables created within the for statement are part of
the body scope of the for statement, not in some kind of implicit "mini"
scope created around the body.  It seems wrong and can lead to bugs and
confusion.  I cannot think of one possible reason why the user would want to
"overwrite" the variables created in the for statement.

Regards

---------------------------------
Q-Games, Dylan Cuthbert.
http://www.q-games.com
P2P internet radio - http://www.peercast.org

"Dylan Cuthbert" <dylan@q-games.com> wrote in message
ain8oa$sqp$1@main.gmane.org">news:ain8oa$sqp$1@main.gmane.org...
>
> Hi there, I am compiling with -Wall and -Werror, surely that should
> include -Wshadow?  If it doesn't currently, then I suggest it should be.
>
> The scoping seems strange in gcc, is that the iso-standard?  ie. the for
> statement is making *two* scopes, one to scope the variables created
within
> its statement and the other for the body.
>
> Regards
>
> ---------------------------------
> Q-Games, Dylan Cuthbert.
> http://www.q-games.com
> P2P internet radio - http://www.peercast.org
>
> "Fergus Henderson" <fjh@cs.mu.OZ.AU> wrote in message
> 20020805141033.GA22390@ceres.cs.mu.oz.au">news:20020805141033.GA22390@ceres.cs.mu.oz.au...
> > That's what `-Wshadow' is for.
> >
> > Were you compiling with `-Wshadow' enabled?
> >
> > On 05-Aug-2002, Dylan Cuthbert <dylan@q-games.com> wrote:
> > >
> > > for ( int i = 0; i < 10; i++ )
> > > {
> > >     int i = 10;       <===== shadowing the i variable
> > >     printf( "%d\n", i  );
> > > }
> > >
> > >
> > > To my understanding, the "int i" in the for statement is within the
> scope of
> > > the following curly brackets?
> > >
> > > If this isn't an error (ie. there is a special "mini" scope created
> around
> > > the for statement's scope), then it *definitely* *definitely* (pretty
> > > please) should throw up a warning.  I just spent a while looking at
some
> > > code before realising it was something as silly as this.
> > >
> > > Regards
> > >
> > > ---------------------------------
> > > Q-Games, Dylan Cuthbert.
> > > http://www.q-games.com
> > > P2P internet radio - http://www.peercast.org
> > >
> > >
> > >
> >
> > --
> > Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the
> pursuit
> > The University of Melbourne         |  of excellence is a lethal habit"
> > WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S.
Garp.
> >
>
>
>
>




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