[Issue 3809] New: Struct initializers apparently always CTFE'd, and incorrectly
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Feb 16 14:25:36 PST 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3809
Summary: Struct initializers apparently always CTFE'd, and
incorrectly
Product: D
Version: 1.056
Platform: All
OS/Version: All
Status: NEW
Keywords: diagnostic, rejects-valid, wrong-code
Severity: regression
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: matti.niemenmaa+dbugzilla at iki.fi
--- Comment #0 from Matti Niemenmaa <matti.niemenmaa+dbugzilla at iki.fi> 2010-02-16 14:25:34 PST ---
This worked at least as late as 1.051, but now fails in 1.056:
struct S { int xx; int x() { return xx; } }
void foo(S s) {
S a = {100 / s.x()};
S b = {100 / s.x()};
}
$ dmd arst.d
Error: divide by 0
arst.d(4): Error: cannot evaluate s.x() at compile time
It seems like it's CTFEing the s.x() calls, which would explain the (bonus:
location-lacking) division by zero error as well: xx is zero by default, after
all.
Confirmed by changing "int xx" to "int xx = 1" and returning b from foo: the
code compiles, and the disassembly shows that no divisions are being performed,
it was erroneously done at compile time. Similarly, changing the code to
perform e.g. a multiplication instead of a division makes it compile (as the
division by zero is the cause for the lack of compilation), but again the s.x()
has been improperly CTFE'd.
An additional point of interest: the "cannot evaluate" error is only reported
for the S's after the first: with only one, the code compiles (to wrong code,
again).
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list