Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
TypeInfo: implement TypeInfo.init, because it is called by LDC when u…
Browse files Browse the repository at this point in the history
…sing typeof(null) types.
  • Loading branch information
JohanEngelen committed Feb 10, 2016
1 parent b907ceb commit 2cdd96b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/object.d
Expand Up @@ -302,7 +302,18 @@ class TypeInfo

/// Return default initializer. If the type should be initialized to all zeros,
/// an array with a null ptr and a length equal to the type size will be returned.
version(LDC)
{
// LDC uses TypeInfo's vtable for the typeof(null) type:
// %"typeid(typeof(null))" = type { %object.TypeInfo.__vtbl*, i8* }
// Therefore this class cannot be abstract, and all methods need implementations.
// Tested by test14754() in runnable/inline.d, and a unittest below.
const(void)[] init() nothrow pure const @safe @nogc { return null; }
}
else
{
abstract const(void)[] init() nothrow pure const @safe @nogc;
}

/// Get flags for type: 1 means GC should scan for pointers,
/// 2 means arg of this type is passed in XMM register
Expand Down Expand Up @@ -333,6 +344,11 @@ class TypeInfo
@property immutable(void)* rtInfo() nothrow pure const @safe @nogc { return null; }
}

version(LDC) unittest
{
auto t = new TypeInfo; // test that TypeInfo is not an abstract class. Needed for instantiating typeof(null).
}

class TypeInfo_Typedef : TypeInfo
{
override string toString() const { return name; }
Expand Down

1 comment on commit 2cdd96b

@dnadlinger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, see https://issues.dlang.org/show_bug.cgi?id=15680.

Looks like this is also a problem with DMD, but doesn't get triggered in the test suite.

Please sign in to comment.