Bug 2155 – case statements always start new scope

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2008-06-19T09:22:00Z
Last change time
2014-02-24T15:33:06Z
Keywords
spec
Assigned to
bugzilla
Creator
kamm-removethis

Comments

Comment #0 by kamm-removethis — 2008-06-19T09:22:15Z
Scope statements introduce a new scope even when not using ScopeBlockStatement, as seen here: switch(1) { case 1: writefln("case 1"); scope(exit) writefln("case 1 scope exit"); case 2: writefln("fallthrough to 2"); } prints: case 1 case 1 scope exit fallthrough to 2 But this behaviour is not described in the spec. Maybe add: "Case statements start a scope that ends at the end of the enclosing scope or before the next case or default statement that is inside the same scope level. Example: switch(i) { case 1: // implicit scope start 1 ... // implicit scope end 1 case 2: // implicit scope start 2 while(true) { case 3: // implicit scope start 3 // implcit scope end 3 } // implicit scope end 2 } "
Comment #1 by kamm-removethis — 2008-06-20T08:09:57Z
*** This bug has been marked as a duplicate of 603 ***