D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6713 - Segfault with typeid of an alias
Summary: Segfault with typeid of an alias
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-22 03:44 UTC by Don
Modified: 2012-01-28 15:25 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2011-09-22 03:44:21 UTC
From the test suite, test1() in testtypeid.d, if 'typedef' is replaced by 'alias', a runtime segfault occurs. It works if typedef is used instead.

import std.stdio;

class ABC { }

alias ABC DEF; // typedef ABC DEF; is OK.

TypeInfo foo()
{
    ABC c;

    return typeid(DEF);
}

void main()
{
    TypeInfo ti = foo();
    TypeInfo_Typedef td = cast(TypeInfo_Typedef)ti;
    assert(td);

    ti = td.base;

    TypeInfo_Class tc = cast(TypeInfo_Class)ti;
    assert(tc);

    printf("%.*s\n", tc.info.name.length, tc.info.name.ptr);
    assert(tc.info.name == "testtypeid.ABC");
    
}
Comment 1 Walter Bright 2012-01-28 15:25:47 UTC
The problem is this line:

    TypeInfo_Typedef td = cast(TypeInfo_Typedef)ti;

ti is a TypeInfo_Class. There is no TypeInfo_Alias, and an alias isn't a TypeInfo_Typedef.