Why does this work?

Jonathan M Davis jmdavisProg at gmx.com
Thu Feb 17 21:35:16 PST 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 at 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?!

It's a bug. No question.

- Jonathan M Davis


More information about the Digitalmars-d mailing list