D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1811 - TypeInfo usage leads to seg fault at runtime
Summary: TypeInfo usage leads to seg fault at runtime
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P2 normal
Assignee: Walter Bright
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2008-01-30 15:20 UTC by Christian Kamm
Modified: 2015-06-09 01:14 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 Christian Kamm 2008-01-30 15:20:12 UTC
The code

import std.stdio;

class Base
{
    int foo() { return 0; }
}

class Sub : Base
{
    override int foo() { return 0; }
}

void main()
{
   auto t1 = typeid(typeof(Sub.foo));
   auto t2 = typeid(typeof(Base.foo)); // <- comment to fix
   
   t1.tsize(); // crash
}

compiles fine, but crashes when run.
Comment 1 Christian Kamm 2008-01-30 15:26:43 UTC
Note that classes or virtual functions are not responsible. The same behaviour is shown by

import std.stdio;

void main()
{
   int foo() { return 0; }
   int bar() { return 0; }
   
   auto t1 = typeid(typeof(foo));   
   auto t2 = typeid(typeof(bar));
   
   t1.tsize(); // crash
}
Comment 2 Christian Kamm 2008-01-30 15:32:24 UTC
I think it is related to 1522, as I get a multiple definition linker error for _D12TypeInfo_FZi6__initZ when feeding the code to DMD 1.021.
Comment 3 Walter Bright 2008-03-04 23:48:15 UTC
Works in DMD 2.011.
Comment 4 Christian Kamm 2008-03-05 02:25:13 UTC
Both snippets still produce segmentation faults for me using a fresh DMD 2.011 and linux.
Comment 5 Alexey Ivanov 2010-01-27 07:02:48 UTC
Works in DMD 1.055 and DMD 2.039