Skip to content

[BUG] sidecasts via is/as always fail #127

Closed
@gerlero

Description

@gerlero

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:

  1. 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;
}
  1. Command lines including which C++ compiler you are using
    x86-64 gcc 12.2 with -std=c++20 option

  2. Expected result - what you expected to happen
    Program compiles and outputs 1 (i.e., p* is a B2)

  3. Actual result/error
    Program compiles but prints 0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions