public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/2288: Variable declared in for-loop-header is in wrong scope
@ 2002-11-21 5:18 Joseph S. Myers
0 siblings, 0 replies; 2+ messages in thread
From: Joseph S. Myers @ 2002-11-21 5:18 UTC (permalink / raw)
To: gdr; +Cc: gcc-prs
The following reply was made to PR c++/2288; it has been noted by GNATS.
From: "Joseph S. Myers" <jsm28@cam.ac.uk>
To: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
Cc: <gcc-gnats@gcc.gnu.org>, <gcc-bugs@gcc.gnu.org>
Subject: Re: c++/2288: Variable declared in for-loop-header is in wrong scope
Date: Fri, 15 Nov 2002 00:14:23 +0000 (GMT)
On Thu, 14 Nov 2002, Wolfgang Bangerth wrote:
> The C frontend in gnu99 mode suffers from the same problem, by the way.
Not a bug for C99. See 6.8.5#5.
--
Joseph S. Myers
jsm28@cam.ac.uk
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: c++/2288: Variable declared in for-loop-header is in wrong scope
@ 2002-11-21 4:33 Wolfgang Bangerth
0 siblings, 0 replies; 2+ messages in thread
From: Wolfgang Bangerth @ 2002-11-21 4:33 UTC (permalink / raw)
To: gdr; +Cc: gcc-prs
The following reply was made to PR c++/2288; it has been noted by GNATS.
From: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
To: gcc-gnats@gcc.gnu.org, <gcc-bugs@gcc.gnu.org>
Cc:
Subject: Re: c++/2288: Variable declared in for-loop-header is in wrong scope
Date: Thu, 14 Nov 2002 18:13:47 -0600 (CST)
Still happens with recent CVS. A smaller, self-contained testcase is this:
------------------------
void f(int);
int main() {
for (int i=0;;++i) {
int i=5;
f(i);
}
return 0;
}
-----------------------
I don't get an error upon the second declaration of "i", although it
should be in the same scope as that declared in the loop-header. If I use
-Wshadow, it says
x.cc: In function `int main()':
x.cc:4: warning: declaration of `i' shadows a previous local
x.cc:3: warning: shadowed declaration is here
So one can assume that gcc generates two nested scopes for this construct,
in the outer one those variables are placed which are declared in the loop
header, in the inner one those go that are declared in the loop body. I
think this is not the intent of the standard...
The C frontend in gnu99 mode suffers from the same problem, by the way.
Regards
Wolfgang
-------------------------------------------------------------------------
Wolfgang Bangerth email: bangerth@ticam.utexas.edu
www: http://www.ticam.utexas.edu/~bangerth
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-11-15 0:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-21 5:18 c++/2288: Variable declared in for-loop-header is in wrong scope Joseph S. Myers
-- strict thread matches above, loose matches on Subject: below --
2002-11-21 4:33 Wolfgang Bangerth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).