[Issue 18078] New: [CTFE] wrong initialization of array member with inout opIndex
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Dec 14 16:04:19 UTC 2017
https://issues.dlang.org/show_bug.cgi?id=18078
Issue ID: 18078
Summary: [CTFE] wrong initialization of array member with inout
opIndex
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: simon.buerger at rwth-aachen.de
In the following example, CTFE does not correctly initialize the data field.
Note that the bug disappears if either
- 'inout' is removed or
- 'Complex!double' is replaced by 'double' or
- 'data' is changed from 'Complex!double[1]' to 'Complex!double'
import std.complex;
import std.stdio;
struct Foo
{
Complex!double[1] data;
ref inout(Complex!double) opIndex(size_t i) inout
{
return data[i];
}
this(Complex!double a)
{
this[0] = a;
}
}
void main()
{
enum x = Foo(Complex!double(0));
const y = Foo(Complex!double(0));
writefln("%s", x.data[0]); // prints 'nan+nani' (incorrect)
writefln("%s", y.data[0]); // prints '0.0i' (correct)
}
--
More information about the Digitalmars-d-bugs
mailing list