Using CTFE and enums produces an error in D1, both examples compile in D2.
test1.d
------
int b() { return 10; }
enum { a = b() }
C:>dmd test1.d
test1.d(2): Error: Integer constant expression expected instead of b()
test2.d
------
int b() { return 10; }
enum { a = b }
C:>dmd test2.d
test2.d(2): Error: cannot implicitly convert expression (b) of type int() to int
test2.d(2): Error: Integer constant expression expected instead of cast(int)b
The following is OK in D1.
int b() { return 10; }
const int x = b();
enum { a = x }
Comment #1 by clugdbug — 2009-08-25T04:18:40Z
Patch for the first case: enum.c, EnumDeclaration::semantic, line 109
assert(e->dyncast() == DYNCAST_EXPRESSION);
e = e->semantic(sce);
- e = e->optimize(WANTvalue);
+ e = e->optimize(WANTvalue | WANTinterpret);
// Need to copy it because we're going to change the type
e = e->copy();
e = e->implicitCastTo(sc, memtype);
- e = e->optimize(WANTvalue);
+ e = e->optimize(WANTvalue | WANTinterpret);
number = e->toInteger();
e->type = t;
Comment #2 by razvan.nitu1305 — 2019-09-24T13:54:33Z