[Issue 11553] dmd segfault with recursive template

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Nov 19 06:42:46 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=11553



--- Comment #3 from John Colvin <john.loughran.colvin at gmail.com> 2013-11-19 14:42:42 GMT ---
Finally, a correct (should compile) example that causes a segfault. It's still
a little large, sorry:

struct Pack(T ...)
{
    alias Unpack = T;
    enum length = T.length;
}

template isPack(TList ...)
{
    static if(TList.length == 1 &&
          is(Pack!(TList[0].Unpack) == TList[0]))
    {
    enum isPack = true;
    }
    else
    {
    enum isPack = false;
    }
}

template PartialApply(alias T, uint argLoc, Arg ...)
    if(Arg.length == 1)
{
    template PartialApply(L ...)
    {
    alias PartialApply = T!(L[0 .. argLoc], Arg, L[argLoc .. $]);
    }
}

template _hasLength(size_t len, T)
{
    static if(T.length == len)
    {
    enum _hasLength = true;
    }
    else
    {   
    enum _hasLength = false;
    }
}

alias _hasLength(size_t len) = PartialApply!(._hasLength, 0, len);


alias hl1 = _hasLength!1;

//this segfaults
static if(!isPack!hl1){ pragma(msg, "All good 1"); }

//these are fine
static if(hl1!(Pack!(5))) { pragma(msg, "All good 2"); }

static if(!hl1!(Pack!())) { pragma(msg, "All good 3"); }


The result:
Program received signal SIGSEGV, Segmentation fault.
0x0000000000434a45 in Dsymbol::Dsymbol(Identifier*) ()

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list