2203 – typeof(class.template.foo) crashes compiler

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2203 - typeof(class.template.foo) crashes compiler
Summary: typeof(class.template.foo) crashes compiler
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords: ice-on-invalid-code, patch
: 1340 (view as issue list)
Depends on:
Blocks:
Reported: 2008年07月08日 12:49 UTC by Max Samukha
Modified: 2014年02月24日 15:59 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Max Samukha 2008年07月08日 12:49:02 UTC
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 Stewart Gordon 2008年11月24日 07:50:26 UTC
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 Don 2009年04月02日 14:15:21 UTC
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 Don 2009年04月18日 01:05:13 UTC
Fixed DMD2.028, not yet fixed in D1.
Comment 4 Don 2009年04月19日 01:36:47 UTC
*** Bug 1340 has been marked as a duplicate of this bug. ***
Comment 5 Don 2009年04月19日 01:46:45 UTC
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();
}
Comment 6 Walter Bright 2009年05月02日 08:51:20 UTC
Fixed dmd 1.044


AltStyle によって変換されたページ (->オリジナル) /