Bug 6095 – switch executes code it shouldn't

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-06-02T23:27:20Z
Last change time
2024-12-13T17:55:26Z
Assigned to
No Owner
Creator
Brad Roberts
See also
https://issues.dlang.org/show_bug.cgi?id=14532
Moved to GitHub: dmd#17526 →

Comments

Comment #0 by braddr — 2011-06-02T23:27:20Z
From runnable/sdtor.d, test 51: int A51_a; struct A51 { ~this() { ++A51_a; } } void test51() // an excerpt from the full test { // should fail to build, no case 1 and no default A51_a = 0; { if (0) final switch(1) A51 a; } assert(A51_a == 0); // should be 0, there's no flow that should involve a being instantiated // or destroyed A51_a = 0; { if (1) switch(1) { A51 a; default: } } assert(A51_a == 1); }
Comment #1 by dlang-bugzilla — 2017-07-05T16:05:57Z
(In reply to Brad Roberts from comment #0) > // should be 0, there's no flow that should involve a being instantiated > // or destroyed > A51_a = 0; { if (1) switch(1) { A51 a; default: } } assert(A51_a == 1); This is now a deprecation (since https://github.com/dlang/dmd/pull/5869).
Comment #2 by robert.schadek — 2024-12-13T17:55:26Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17526 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB