FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[BUG] sidecasts via is/as always fail · Issue #127 · hsutter/cppfront · GitHub

Repository navigation

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

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:

  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

Activity

  1. hsutter commented on Dec 13, 2022

    Owner

    Thanks @gerlero and @filipsajdak!

    I think this is now fixed with #128, and I tried the example and it seems to be correct now.

  2. gerlero commented on Dec 15, 2022

    ContributorAuthor

    The is case seems to be fixed. However, the same sidecast with as is still failing.

    Unfortunately, my example didn't explicitly cover that case (although replacing is->as in the snippet is enough; the cast will evaluate to nullptr even though it shouldn't). I can open a new issue for the as case if it helps with tracking.

  3. filipsajdak commented on Dec 15, 2022

    Contributor

    Yes, you are right. as will not work for sidecast.

    In #106 I have covered handling bad as casts.

    I have noticed that as for sidecast is missing - it requires bad cast handling. If the proposed solution for handling bad casts is accepted by @hsutter, I can provide a proper as cast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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


      Back | FazBrowse Home | New Git URL