Bug 1625 – CTFE: cannot evaluate function when return type includes a union
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2007-10-29T04:51:00Z
Last change time
2015-01-20T16:56:33Z
Keywords
CTFE, rejects-valid
Assigned to
nobody
Creator
spam
Comments
Comment #0 by spam — 2007-10-29T04:51:01Z
dmd refuses to compile the following legal code:
[CODE]
struct Foo {
union {
struct {
float x,y,z;
}
float[3] _v;
}
static Foo bar(){
Foo f;
return f;
}
}
void main() {
const Foo foo = Foo.bar();//Error: cannot evaluate bar() at compile time
}
[/CODE]
i hope i am right that it should work and is valid code.
Comment #1 by spam — 2007-11-28T03:37:39Z
this examples seems to work now, was it intentionally fixed in 2.008? it's not in the changelog.
Comment #2 by spam — 2007-11-29T06:56:05Z
ok the above example works under dmd2.008 just cause of the changes in the const thing, when involving static it isnt able to evaluate the union stuff @compile time again:
[CODE]
struct Foo {
union {
struct {
float x,y,z;
}
float[3] _v;
}
static Foo bar(){
Foo f;
return f;
}
}
void main() {
static Foo foo = Foo.bar();//Error: cannot evaluate bar() at compile time
}
[/CODE]
Comment #3 by clugdbug — 2009-08-26T09:45:28Z
Actually it cannot evaluate any function which involves reading the value of a union. (It can WRITE to a union, though!)
Comment #4 by k.hara.pg — 2015-01-20T16:56:33Z
From about 2.055, the code works properly in CTFE.