www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14331] New: Can't call `destroy()` on a class with `alias


          Issue ID: 14331
           Summary: Can't call `destroy()` on a class with `alias this` on
                    a struct field
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: initrd.gz gmail.com

This code:

    class Test {
        struct Foo {
            int a, b, c;

        Foo foo;
        alias foo this;

    void main() {
        auto test = new Test();

Fails to compile with the following message:

    $ rdmd test.d
    c:\D\dmd2\windows\bin\..\..\src\druntime\import\object.di(523): Error:
cannot cast from Foo to void*
    test.d(13): Error: template instance object.destroy!(Test) error
    Failed: ["dmd", "-v", "-o-", "test.d", "-I."]

Presumably because the `cast(void*)` is trying to cast the struct that is
aliased instead of the class. Removing the `alias foo this` causes the code to

Using version 2.066.1 at the moment, but I didn't see anything related in the
changelog for v2.067.

Mar 24 2015