Thread overview
[Issue 2203] New: typeof(class.template.foo) crashes compiler
Jul 08, 2008
d-bugmail
Nov 24, 2008
d-bugmail
Apr 02, 2009
d-bugmail
Apr 18, 2009
d-bugmail
Apr 19, 2009
d-bugmail
Apr 19, 2009
d-bugmail
May 02, 2009
d-bugmail
July 08, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2203

           Summary: typeof(class.template.foo) crashes compiler
           Product: D
           Version: 2.015
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: samukha@voliacable.com


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


-- 

November 24, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2203


smjg@iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com
           Keywords|                            |ice-on-invalid-code




------- Comment #1 from smjg@iname.com  2008-11-24 07:50 -------
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;


-- 

April 02, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2203


clugdbug@yahoo.com.au changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
            Version|2.015                       |1.031




------- Comment #2 from clugdbug@yahoo.com.au  2009-04-02 14:15 -------

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.


-- 

April 18, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2203





------- Comment #3 from clugdbug@yahoo.com.au  2009-04-18 01:05 -------
Fixed DMD2.028, not yet fixed in D1.


-- 

April 19, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2203


clugdbug@yahoo.com.au changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dvdfrdmn@users.sf.net




------- Comment #4 from clugdbug@yahoo.com.au  2009-04-19 01:36 -------
*** Bug 1340 has been marked as a duplicate of this bug. ***


-- 

April 19, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2203





------- Comment #5 from clugdbug@yahoo.com.au  2009-04-19 01:46 -------
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();
}


-- 

May 02, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2203


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #6 from bugzilla@digitalmars.com  2009-05-02 08:51 -------
Fixed dmd 1.044


--