The following causes the compiler to crash (both 1.031 and 2.015):
class C
{
template Bar()
{
}
}
static assert(!is(typeof(C.Bar.foo))); // Should pass
Comment #1 by smjg — 2008-11-24T07:50:26Z
Though the code above is valid, I'm marking this as ice-on-invalid-code because the root cause of it is that the compiler crashes trying to make sense of the invalid typeof.
class C
{
template Bar()
{
}
}
typeof(C.Bar.foo) quux;
Comment #2 by clugdbug — 2009-04-02T14:15:21Z
The segfault is caused by this line in DotIdExp::semantic(Scope *sc)
in expression.c, line 5348 (in DMD 2.027).
Type *t1b = e1->type->toBasetype();
If the expression was invalid, e1->type is null, so it segfaults.
Adding a line like:
if (!e1->type) {error("invalid expression"); return e1;}
before line 5348 is sufficient to avoid the segfault, and the original valid code will compile without error. Not sure what the error message should be, though.
Comment #3 by clugdbug — 2009-04-18T01:05:13Z
Fixed DMD2.028, not yet fixed in D1.
Comment #4 by clugdbug — 2009-04-19T01:36:47Z
*** Bug 1340 has been marked as a duplicate of this bug. ***
Comment #5 by clugdbug — 2009-04-19T01:46:45Z
This is actually the same as bug 1340. The typeof() isn't necessary. The error message should be something like: "Uninstantiated templates have no members".
Reduced test case, ultimately from bug 1340:
struct C {
template Bar() {}
}
void main() {
C.Bar.foo();
}