You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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 outputs 1 (i.e., p*is a B2)
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).
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.
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.
Activity
hsutter commentedon Dec 13, 2022
Thanks @gerlero and @filipsajdak!
I think this is now fixed with #128, and I tried the example and it seems to be correct now.
gerlero commentedon Dec 15, 2022
The
iscase seems to be fixed. However, the same sidecast withasis still failing.Unfortunately, my example didn't explicitly cover that case (although replacing
is->asin the snippet is enough; the cast will evaluate tonullptreven though it shouldn't). I can open a new issue for theascase if it helps with tracking.filipsajdak commentedon Dec 15, 2022
Yes, you are right.
aswill not work for sidecast.In #106 I have covered handling bad
ascasts.I have noticed that
asfor sidecast is missing - it requires bad cast handling. If the proposed solution for handling bad casts is accepted by @hsutter, I can provide a properascast.