Thread overview
[dmd-internals] ClassInfo for C++ classes in DMD
Jul 07, 2016
Jacob Carlborg
Jul 07, 2016
Walter Bright
Jul 07, 2016
Jacob Carlborg
Jul 07, 2016
Walter Bright
July 07, 2016
Usually a C++ class in D doesn’t have any type info available, i.e. calling “object.classinfo” will return null. But for some reason the C++ classes (declared in D) in DMD will return a non-null value when calling “object.classinfo”, why is that?

—
/Jacob Carlborg
_______________________________________________
dmd-internals mailing list
dmd-internals@puremagic.com
http://lists.puremagic.com/mailman/listinfo/dmd-internals
July 07, 2016

On 7/7/2016 3:08 AM, Jacob Carlborg via dmd-internals wrote:
> Usually a C++ class in D doesn’t have any type info available, i.e. calling
> “object.classinfo” will return null. But for some reason the C++ classes
> (declared in D) in DMD will return a non-null value when calling
> “object.classinfo”, why is that?

C++ classes have no dynamic type info (i.e. what the most derived class is). But they do have static type info.
_______________________________________________
dmd-internals mailing list
dmd-internals@puremagic.com
http://lists.puremagic.com/mailman/listinfo/dmd-internals
July 07, 2016
> On 07 Jul 2016, at 12:23, Walter Bright via dmd-internals <dmd-internals@puremagic.com> wrote:
> 
> C++ classes have no dynamic type info (i.e. what the most derived class is). But they do have static type info.

What I mean is this:

// first example, unrelated to the DMD codebase

extern(C++) class Foo {}

void main ()
{
    auto a = new Foo;
    assert(a.classinfo is null);
}

// second example, somewhere inside the DMD codebase

auto a = new IntegerExp(0);
assert(a.classinfo !is null);

Both of the above assertions pass. My question is why the second assertion pass.

—
/Jacob Carlborg
_______________________________________________
dmd-internals mailing list
dmd-internals@puremagic.com
http://lists.puremagic.com/mailman/listinfo/dmd-internals
July 07, 2016

On 7/7/2016 5:43 AM, Jacob Carlborg wrote:
>
>> On 07 Jul 2016, at 12:23, Walter Bright via dmd-internals <dmd-internals@puremagic.com> wrote:
>>
>> C++ classes have no dynamic type info (i.e. what the most derived class is). But they do have static type info.
>
> What I mean is this:
>
> // first example, unrelated to the DMD codebase
>
> extern(C++) class Foo {}
>
> void main ()
> {
>     auto a = new Foo;
>     assert(a.classinfo is null);
> }
>
> // second example, somewhere inside the DMD codebase
>
> auto a = new IntegerExp(0);
> assert(a.classinfo !is null);
>
> Both of the above assertions pass. My question is why the second assertion pass.

I don't know. I suspect there is more to it than the snippet here.
_______________________________________________
dmd-internals mailing list
dmd-internals@puremagic.com
http://lists.puremagic.com/mailman/listinfo/dmd-internals