Assertion failure: 'dest->op == TOKstructliteral || dest->op == TOKarrayliteral || dest->op == TOKstring' on line 1604 in file 'ctfeexpr.c'
and
Error: cannot dereference invalid pointer *chunk
//----------------
static struct S
{
}
struct SS
{
S s2; //[1]
this(S s1)
{
//S s2; //[2]
emplace(&s2, s1);
}
}
void emplace(S* chunk, S arg)
{
emplacePostblitter(*chunk, arg); //[3]
*chunk = arg; //[4]
}
private void emplacePostblitter(ref S chunk, S arg)
{
chunk = arg;
}
enum s = S();
enum p = SS(s);
//----------------
Getting two different errors:
[3] : //Assertion failure: 'dest->op == TOKstructliteral || dest->op == TOKarrayliteral || dest->op == TOKstring' on line 1604 in file 'ctfeexpr.c'
If we comment [3], then it is [4] that errors:
[4] Error: cannot dereference invalid pointer *chunk
Interesting enough, if we move line [1] to line [2], then everything works fine.
Comment #1 by wazar.leollone — 2013-04-23T07:03:08Z
I've tried to simplify this bug case.
My resolution: error in operation of taking address of struct member and dereference it.
We must ask Don about this.
struct Foo(T)
{
T a;
this(T arg)
{
T* p = &a;
*p = arg;
}
this(T arg, int)
{
T* p = &a;
setRef(*p, arg);
}
static void setRef(ref T p, T v)
{
p = v;
}
}
auto ct1 = Foo!int(99); //compiled, but doesn't set this.a to 99
auto ct2 = Foo!int(99, 0); //compiled, but doesn't set this.a to 99
//try with struct
struct Bar
{
int b;
}
auto ct1_2 = Foo!Bar(Bar(99)); //Error
auto ct2_2 = Foo!Bar(Bar(99), 0); //ICE
void main()
{
assert(ct1.a != 99);
assert(ct2.a != 99);
}
Comment #2 by clugdbug — 2013-07-09T02:00:27Z
This is a critical bug. Assignment via a pointer to a struct member does not work!
struct Bug9982 {
int a;
}
int test9982()
{
Bug9982 x;
int *q = &x.a;
*q = 99;
assert(x.a == 99);
return 1;
}
static assert(test9982());
Comment #3 by github-bugzilla — 2013-08-26T23:56:25Z