[Issue 751] New: Compiler segfault on template expansion

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 26 11:36:54 PST 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 at digitalmars.com
        ReportedBy: sean at 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.


-- 



More information about the Digitalmars-d-bugs mailing list