Skip to content

Commit 35b4427

Browse files
committed
[clang][bytecode] Don't outright reject dyamic casts
Just delegate to the subexpr instead.
1 parent 0400b9a commit 35b4427

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,11 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
773773
case CK_ToVoid:
774774
return discard(SubExpr);
775775

776+
case CK_Dynamic:
777+
// This initially goes through VisitCXXDynamicCastExpr, where we emit
778+
// a diagnostic if appropriate.
779+
return this->delegate(SubExpr);
780+
776781
default:
777782
return this->emitInvalid(CE);
778783
}

clang/test/AST/ByteCode/cxx20.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,3 +1201,13 @@ namespace NonPureVirtualCall {
12011201

12021202
int main() { check(); }
12031203
}
1204+
1205+
namespace DyamicCast {
1206+
struct X {
1207+
virtual constexpr ~X() {}
1208+
};
1209+
struct Y : X {};
1210+
constexpr Y y;
1211+
constexpr const X *p = &y;
1212+
constexpr const Y *q = dynamic_cast<const Y*>(p);
1213+
}

0 commit comments

Comments
 (0)