Article View: gnu.g++.bug
Article #600Gotos past local variable initialization
From: Michael Tiemann
Date: Sun, 19 Nov 1989 05:29
Date: Sun, 19 Nov 1989 05:29
49 lines
1794 bytes
1794 bytes
Date: 18 Nov 89 21:22 -0800
From: Mike Bolotski <mikeb@ee.ubc.ca>
I'm not sure if this is a g++ bug or a V2.0 feature. In any case,
similar code worked fine under 1.35. The compiler complains about
the jump past the initialization point. In this example, the goto
can be replaced by a continue; in the actual application, the goto
is used as a continue(3) equivalent (continue with loop 3 levels out),
so no flames about goto's. Please.
-----
coho{mikeb}101: g++ -v lambda.cc
[...]
lambda.cc: In function int main ():
lambda.cc:14: invalid jump to label `nextp'
lambda.cc:11: crosses initialization of `q'
coho{mikeb}102: cat lambda.cc
#include <stdio.h>
int main()
{
for (int p = 100; p ; ) {
if (p > 10)
goto nextp;
short q = 7 * p;
if (q > 4)
printf("Hello\n");
nextp: ;
}
}
coho{mikeb}103: exit
exit
It's a 2.0 feature. cfront 2.0 also gives an error:
cfront < l5.cc > /dev/null
"", line 9: error: goto nextp past initialized q
teacake%
Both compilers will let you use continue. If you want a work-around,
just wrap `q' in a scope which makes it invisible at `nextp'.
Michael
Technical Details
Message-ID:
<8911190529.AA11423@lurch.Stanford.EDU>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!tmsoft!torsqnt!jarvis.csri.toronto.edu!rutgers!apple!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!lurch.stanford.edu!tiemannReferences:
<285*mikeb@ee.ubc.ca>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!tmsoft!torsqnt!jarvis.csri.toronto.edu!rutgers!apple!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!lurch.stanford.edu!tiemann From: tiemann@lurch.stanford.edu (Michael Tiemann) Newsgroups: gnu.g++.bug Subject: Gotos past local variable initialization Message-ID: <8911190529.AA11423@lurch.Stanford.EDU> Date: 19 Nov 89 05:29:22 GMT References: <285*mikeb@ee.ubc.ca> Sender: daemon@tut.cis.ohio-state.edu Reply-To: tiemann@lurch.stanford.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 49