Thread overview | ||||||
---|---|---|---|---|---|---|
|
October 07, 2011 [Issue 6784] New: Compile-time constant assigned with a runtime value | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=6784 Summary: Compile-time constant assigned with a runtime value Product: D Version: D2 Platform: x86 OS/Version: Windows Status: NEW Keywords: accepts-invalid Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: bearophile_hugs@eml.cc --- Comment #0 from bearophile_hugs@eml.cc 2011-10-07 15:37:34 PDT --- This program compiles with no errors (DMD 2.056head), but I think it's wrong because the compile-time constant y gets assigned with a runtime value: struct Foo { immutable uint x; void foo() { enum uint y = x; } } void main(string[] args) { auto f = Foo(args.length); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 01, 2012 [Issue 6784] Compile-time constant assigned with a runtime value | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=6784 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |yebblies@gmail.com Platform|x86 |All Version|D2 |D1 & D2 AssignedTo|nobody@puremagic.com |clugdbug@yahoo.com.au OS/Version|Windows |All --- Comment #1 from yebblies <yebblies@gmail.com> 2012-02-01 13:09:43 EST --- Related to Issue 2414. What differs here is that enum uint y = x Is translated to enum uint y = this.x And DotIdExp::optimize does not turn this into a constant value, and there is no error when it fails when called with result & WANTinterpret. Unfortunately adding an error causes problems with other code, presumably because DotIdExp::optimize is use from other places like CallExp::optimize that expect it to just try and finish without errors. Reassigning to Don as he fixed 2414 and understands the constfolding/interpreter code a lot better than I do. Probably applies to D1/const variables too. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 22, 2012 [Issue 6784] Compile-time constant assigned with a runtime value | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=6784 --- Comment #2 from Don <clugdbug@yahoo.com.au> 2012-02-22 01:14:30 PST --- The error message should only happen when result & WANTinterpret. But, the problem is, as usual, those %&/$# AAs. The builtin AA properties aren't converted into function calls. Rather than add another hack for this, it's probably better to wait for bug 5590 to be pulled in. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 22, 2012 [Issue 6784] Compile-time constant assigned with a runtime value | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=6784 --- Comment #3 from Don <clugdbug@yahoo.com.au> 2012-02-22 11:59:55 PST --- FWIW, this patch in optimize.c, DotVarExp::optimize() fixes the bug. But, the exclusion of TOKassocarrayliteral is just a hack. if (e && e->op == TOKstructliteral) { StructLiteralExp *sle = (StructLiteralExp *)e; VarDeclaration *vf = var->isVarDeclaration(); if (vf) { Expression *e = sle->getField(type, vf->offset); if (e && e != EXP_CANT_INTERPRET) return e; } } + else if (result & WANTinterpret && (!e || e->op != TOKassocarrayliteral)) + error("%s cannot be evaluated at compile time", e1->toChars()); return this; } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation