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(); }
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.
Replace 'const' with 'static const' and this fails on D2.040 and later, but passed on 2.039 and earlier.
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;
http://www.dsource.org/projects/dmd/changeset/708
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル