www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Bug with labeled breaks

reply BCS <BCS_member pathlink.com> writes:
The following code compiles as-is without complaint on 0.129(win) but when it’s
run it gets stuck in the second loop (line 6).
There must be a bug in here somewhere. Either the "break foo" should exit the
labeled block statement (hmm… that’s a thought) or it shouldn’t compile. Ether
way the second loop should be unreachable.



void main()
{
foo:
{
while(true)break foo;
while(true){}    //line 6
}
}
Aug 11 2005
parent =?UTF-8?B?VGhvbWFzIEvDvGhuZQ==?= writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

BCS schrieb:

 The following code compiles as-is without complaint on 0.129(win) but when
it’s
 run it gets stuck in the second loop (line 6).
 There must be a bug in here somewhere. Either the "break foo" should exit the
 labeled block statement (hmm… that’s a thought) or it shouldn’t compile.
Ether
 way the second loop should be unreachable.
 
 
 
 void main()
 {
 foo:
 {
 while(true)break foo;
 while(true){}    //line 6
 }
 }

http://digitalmars.com/d/statement.html # If break is followed by Identifier, the Identifier must be the label # of an enclosing while, for, do or switch statement, and that statement # is exited. It is an error if there is no such statement. # Any statement can be labelled, including empty statements, and so can # serve as the target of a goto statement. Labelled statements can also # serve as the target of a break or continue statement. ==A== foo:{ while(true){ break foo; } while(true){ assert(0); } } ==B== { foo: while(true){ break foo; } while(true){ assert(0); } } It seems like the compiler is moving the label. in A: labeled BlockStatement in B: labeled WithStatement The code in A is illegal as "foo" doesn't mark "an enclosing while, for, do or switch statement". Added to DStress as http://dstress.kuehne.cn/nocompile/b/break_11_A.d http://dstress.kuehne.cn/nocompile/b/break_11_B.d http://dstress.kuehne.cn/nocompile/b/break_11_C.d http://dstress.kuehne.cn/nocompile/b/break_11_D.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFC/mg+3w+/yD4P9tIRAidPAJ4gCVXvYpIkSOrCjzW6M0hX7cMiEgCfciuV Byuy1EKTbIyzVPhDnWvAbmo= =8OLc -----END PGP SIGNATURE-----
Aug 13 2005