digitalmars.D - Why does this work?
- Vladimir Panteleev (10/10) Feb 17 2011 int foo;
- Jason House (2/14) Feb 17 2011 I would have expected bar to equal 2 since foo would be default initiali...
- Jonathan M Davis (9/25) Feb 17 2011 I believe that the bug here is that bar is allowed to use foo in its
- Andrei Alexandrescu (3/27) Feb 17 2011 Posted, search bugzilla for "yum".
- Vladimir Panteleev (16/21) Feb 17 2011 Nope:
- Jonathan M Davis (3/27) Feb 17 2011 It's a bug. No question.
- Don (2/11) Feb 17 2011 It's bug 2414 "enum is dynamically evaluated, yum"
int foo; enum bar = foo+2; void main() { foo = 7; assert(bar == 9); } -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Feb 17 2011
Vladimir Panteleev Wrote:int foo; enum bar = foo+2; void main() { foo = 7; assert(bar == 9); } -- Best regards, Vladimir mailto:vladimir thecybershadow.netI would have expected bar to equal 2 since foo would be default initialized to 2. I'm going to guess that the there's some kind of optimization that only assigns to foo once and isn't noticing that bar depends on it. You should probably post that in bugzilla.
Feb 17 2011
On Thursday 17 February 2011 21:06:26 Jason House wrote:Vladimir Panteleev Wrote:I believe that the bug here is that bar is allowed to use foo in its initialization. foo isn't immutable or an enum, so that shouldn't work. bar probably gets replaced with foo + 2, which would be perfectly legitimate were foo actually immutable. And the foo + 2 probably doesn't get optimized out like it should be, because foo isn't actually immutable like it would have to be (per the spec) to be used in bar's initialization. This is _definitely_ a bug. - Jonathan M Davisint foo; enum bar = foo+2; void main() { foo = 7; assert(bar == 9); }I would have expected bar to equal 2 since foo would be default initialized to 2. I'm going to guess that the there's some kind of optimization that only assigns to foo once and isn't noticing that bar depends on it. You should probably post that in bugzilla.
Feb 17 2011
On 2/17/11 11:22 PM, Jonathan M Davis wrote:On Thursday 17 February 2011 21:06:26 Jason House wrote:Posted, search bugzilla for "yum". AndreiVladimir Panteleev Wrote:I believe that the bug here is that bar is allowed to use foo in its initialization. foo isn't immutable or an enum, so that shouldn't work. bar probably gets replaced with foo + 2, which would be perfectly legitimate were foo actually immutable. And the foo + 2 probably doesn't get optimized out like it should be, because foo isn't actually immutable like it would have to be (per the spec) to be used in bar's initialization. This is _definitely_ a bug.int foo; enum bar = foo+2; void main() { foo = 7; assert(bar == 9); }I would have expected bar to equal 2 since foo would be default initialized to 2. I'm going to guess that the there's some kind of optimization that only assigns to foo once and isn't noticing that bar depends on it. You should probably post that in bugzilla.
Feb 17 2011
On Fri, 18 Feb 2011 07:06:26 +0200, Jason House <jason.james.house gmail.com> wrote:I would have expected bar to equal 2 since foo would be default initialized to 2. I'm going to guess that the there's some kind of optimization that only assigns to foo once and isn't noticing that bar depends on it.Nope: int foo; enum bar = foo+2; void main() { foo = 7; assert(bar == 9); foo++; assert(bar == 10); }You should probably post that in bugzilla.And complain about basically having expression macros?! -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Feb 17 2011
On Thursday 17 February 2011 21:23:26 Vladimir Panteleev wrote:On Fri, 18 Feb 2011 07:06:26 +0200, Jason House <jason.james.house gmail.com> wrote:It's a bug. No question. - Jonathan M DavisI would have expected bar to equal 2 since foo would be default initialized to 2. I'm going to guess that the there's some kind of optimization that only assigns to foo once and isn't noticing that bar depends on it.Nope: int foo; enum bar = foo+2; void main() { foo = 7; assert(bar == 9); foo++; assert(bar == 10); }You should probably post that in bugzilla.And complain about basically having expression macros?!
Feb 17 2011
Vladimir Panteleev wrote:int foo; enum bar = foo+2; void main() { foo = 7; assert(bar == 9); }It's bug 2414 "enum is dynamically evaluated, yum"
Feb 17 2011