Closed
Description
Describe the bug
When attempting to sidecast (in a scenario with multiple inheritance) using the is
/as
syntax, all cast attempts fail—even when an equivalent dynamic_cast
would succeed.
To Reproduce
Steps to reproduce the behavior:
- Sample code - distilled down to minimal essentials please
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;
}
-
Command lines including which C++ compiler you are using
x86-64 gcc 12.2 with-std=c++20
option -
Expected result - what you expected to happen
Program compiles and outputs1
(i.e.,p*
is aB2
) -
Actual result/error
Program compiles but prints0
Additional context
The cpp2::is
and cpp2::as
overloads that would actually try a dynamic_cast
in this situation are never considered because they are currently constrained to downcasts only (with is_base_of
checks in their requires clauses).
EDIT: fix typo in code snippet