Thread overview
[Issue 751] New: Compiler segfault on template expansion
Dec 26, 2006
d-bugmail
Dec 26, 2006
Sean Kelly
Jan 04, 2007
d-bugmail
December 26, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=751

           Summary: Compiler segfault on template expansion
           Product: D
           Version: 0.178
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: sean@f4.ca


First an unrelated error.  A rewrite of std.typetuple gives the following:

    template TypeTuple( TList... )
    {
        alias TList TypeTuple;
    }

    template IndexOf( T, TList... )
    {
        static if( TList.length == 0 )
            const size_t IndexOf = 1;
        else static if( is( T == typeof( TList[0] ) ) )
            const size_t IndexOf = 0;
        else
            const size_t IndexOf = 1 + IndexOf!( T, TList[1 .. $] );
    }

    void main()
    {
        TypeTuple!(int, long) T;
        printf( "%u\n", IndexOf!(long, T) );
    }

Which does not compile:

    C:\code\src\d\test>dmd test
    test.d(13): tuple TList is used as a type
    test.d(13): Error: can only slice tuple types, not void
    test.d(13): Error: void has no value
    test.d(13): Error: incompatible types for ((1) + (IndexOf!(long,int))):
'int' and 'void'
    test.d(19): template instance
test.main.IndexOf!(long,_T_field_0,_T_field_1) error instantiating

This is the error where an extra set of parenthesis are sometimes required for template parameters to evaluate as a type.  Easy enough to fix--change line 13 of the above, giving:

    template TypeTuple( TList... )
    {
        alias TList TypeTuple;
    }

    template IndexOf( T, TList... )
    {
        static if( TList.length == 0 )
            const size_t IndexOf = 1;
        else static if( is( T == typeof( TList[0] ) ) )
            const size_t IndexOf = 0;
        else
            const size_t IndexOf = 1 + IndexOf!( T, (TList[1 .. $]) );
    }

    void main()
    {
        TypeTuple!(int, long) T;
        printf( "%u\n", IndexOf!(long, T) );
    }

Compiling the above segfaults DMD.


-- 

December 26, 2006
d-bugmail@puremagic.com wrote:
> 
>     void main()
>     {
>         TypeTuple!(int, long) T;
>         printf( "%u\n", IndexOf!(long, T) );
>     }
> 
> Which does not compile:
> 
>     C:\code\src\d\test>dmd test
>     test.d(13): tuple TList is used as a type

Just a quick note.  This error (and perhaps some of the others) is because the TypeTuple declaration above doesn't contain an 'alias' prefix.  The crash demonstrated in the second example is sitll a problem, however.
January 04, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=751


bugzilla@digitalmars.com changed:

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




------- Comment #2 from bugzilla@digitalmars.com  2007-01-03 22:12 -------
Fixed DMD 1.00


--