From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29605 invoked by alias); 15 Nov 2002 00:16:03 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 29560 invoked by uid 71); 15 Nov 2002 00:16:01 -0000 Date: Thu, 21 Nov 2002 04:33:00 -0000 Message-ID: <20021115001601.29557.qmail@sources.redhat.com> To: gdr@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Wolfgang Bangerth Subject: Re: c++/2288: Variable declared in for-loop-header is in wrong scope Reply-To: Wolfgang Bangerth X-SW-Source: 2002-11/txt/msg00746.txt.bz2 List-Id: The following reply was made to PR c++/2288; it has been noted by GNATS. From: Wolfgang Bangerth To: gcc-gnats@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