cppfront icon indicating copy to clipboard operation
cppfront copied to clipboard

[FIX] is() function to handle polymorphic sidecast

Open filipsajdak opened this issue 2 years ago • 0 comments

The current implementation is not handling sidecasts.

The code:

struct B1 { virtual ~B1() = default; };

struct B2 { virtual ~B2() = default; };

struct D : B1, B2 {};

main: () -> int = {
    d: D = ();
    p: * B1 = d&;

    std::cout << p* is B2 << std::endl;
}

returns false - the current implementation of is() function is using std::is_base_of that blocks using dynamic_cast for sidecast. The current fix removes the requirement for B2 being a base for B1.

This PR close is() part of the https://github.com/hsutter/cppfront/issues/127

as() will be fixed after finalizing discussion here: https://github.com/hsutter/cppfront/pull/106 (it requires handling case when dynamic_cast will return nullptr or throw bad_cast).

filipsajdak avatar Nov 22 '22 00:11 filipsajdak