Bug 4825 – Regression(1.057, 2.040) "Error: non-constant expression" with -inline

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2010-09-05T15:42:00Z
Last change time
2015-06-09T05:11:42Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
nfxjfg

Comments

Comment #0 by nfxjfg — 2010-09-05T15:42:44Z
This only happens with -inline. It worked on dmd 1.055, but fails on dmd 1.057, 1.061, 1.062 and 1.063. //fails with dmd -c -inline test.d int a() { int r; return r; //Error: non-constant expression r } int b() { return a(); } void c() { void d() { auto e = b(); } const int f = b(); }
Comment #1 by nfxjfg — 2010-09-05T15:46:57Z
I have to add that this bug triggers even when the "const int..." line on function c is in a different function in a different module. This makes it a very non-obvious bug, where you have no idea what is happening.
Comment #2 by clugdbug — 2010-09-09T14:09:58Z
Replace 'const' with 'static const' and this fails on D2.040 and later, but passed on 2.039 and earlier.
Comment #3 by clugdbug — 2010-09-27T13:26:04Z
This was caused by the improvements to CommaExp::interpret, making things like (int x=3, x); into an lvalue, which allows struct constructors to work in CTFE. But inlining can also create peculiar comma expressions. We need to make sure that non-ref returns return rvalues, not lvalues. PATCH interpret.c, ReturnStatement::interpret(), line 566. --- old ---- #if LOG Expression *e = exp->interpret(istate); printf("e = %p\n", e); return e; #else return exp->interpret(istate); #endif --- new --- Expression *e = exp->interpret(istate); if (e == EXP_CANT_INTERPRET) return e; // Convert lvalues into rvalues if (e->op == TOKvar) e = e->interpret(istate); return e;
Comment #4 by bugzilla — 2010-10-08T13:11:12Z