Bug 3021 – D1 CTFE and enums produces error '... constant expression expected'

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2009-05-23T03:41:05Z
Last change time
2019-09-24T13:54:33Z
Keywords
CTFE, patch, rejects-valid
Assigned to
No Owner
Creator
Gide Nwawudu

Comments

Comment #0 by gide — 2009-05-23T03:41:05Z
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
D1 is no longer supported.