www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 751] New: Compiler segfault on template expansion

reply d-bugmail puremagic.com writes:
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.


-- 
Dec 26 2006
next sibling parent Sean Kelly <sean f4.ca> writes:
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.
Dec 26 2006
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=751


bugzilla digitalmars.com changed:

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





Fixed DMD 1.00


-- 
Jan 03 2007