Tested on OSX 10.9, this will cause a segfault in dmd 2.065 in `cast_.d`, where there should be none (it should just return null)
```
interface Node {}
interface WhereCondition {}
interface Whereable {}
class Where
{
Whereable left; // lhs
this(Whereable left ) {
this.left = left;
}
}
class Select : Whereable
{
WhereCondition[] projection;
this(WhereCondition[] projection...) {
this.projection = projection;
}
Where where()
{
return new Where(this);
}
}
class ATable
{
Where where() {
return (new Select(null)).where();
}
}
void main() {
auto users = new ATable();
auto where = users.where();
WhereCondition var = (cast(Select)where.left).projection[0];
auto var2 = cast(Node) var;
}
```
Removing the last line (auto var2 = ...) will cause the crash not to happen, which makes me think the issue is arising when casting to `Node` from type WhereCondition.
Comment #1 by verylonglogin.reg — 2015-04-02T08:47:22Z
`Select` constructor is typesafe variadic function so `projection` array may be constructed on stack and thus contains garbage after function returns, casting this garbage to `Node` fails somewhere in D runtime.
To fix the code replace
---
this.projection = projection;
---
with
---
this.projection = projection.dup; // `dup` is added
---
P.S.
One should be aware of typesafe variadic functions danger and carefully read docs [1].
[1] http://dlang.org/function.html