Bug 18562 – expression is not evaluated when accessing manifest constant

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2018-03-06T12:31:47Z
Last change time
2018-03-09T21:07:31Z
Keywords
wrong-code
Assigned to
No Owner
Creator
FeepingCreature

Comments

Comment #0 by default_357-line — 2018-03-06T12:31:47Z
Consider: struct Struct { enum Enum = 5; } Struct foo() { while (true) { } return Struct(); } void main() { auto value = foo().Enum; assert(false); } The assert trips, despite the fact that foo() should loop indefinitely, because the compiler optimizes away the call to foo entirely. This is highly unintuitive and also responsible for bug #18560 . Is this really intended?
Comment #1 by ag0aep6g — 2018-03-09T21:07:31Z
*** This issue has been marked as a duplicate of issue 12486 ***