Skip to content

Cannot get the instance pointer of a class if opCast matches #22260

@rikkimax

Description

@rikkimax

Once a matching opCast is declared in a class, it is no longer possible to obtain the instance pointer needed for memory deallocation.

class Foo {
    auto opCast(T)() {
        return this;
    }
}

void main() {
    Foo foo = new Foo;
    void* ptr = cast(void*)foo; // Error: cannot implicitly convert expression `foo.opCast()` of type `example.Foo` to `void*`
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions