https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/167517
Just delegate to the subexpr instead. >From 35b4427346ab8b202adad6d8867dcb697995b94a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Tue, 11 Nov 2025 16:01:46 +0100 Subject: [PATCH] [clang][bytecode] Don't outright reject dyamic casts Just delegate to the subexpr instead. --- clang/lib/AST/ByteCode/Compiler.cpp | 5 +++++ clang/test/AST/ByteCode/cxx20.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 1243380ca8a6b..dfd99f836d0f8 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -773,6 +773,11 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { case CK_ToVoid: return discard(SubExpr); + case CK_Dynamic: + // This initially goes through VisitCXXDynamicCastExpr, where we emit + // a diagnostic if appropriate. + return this->delegate(SubExpr); + default: return this->emitInvalid(CE); } diff --git a/clang/test/AST/ByteCode/cxx20.cpp b/clang/test/AST/ByteCode/cxx20.cpp index cb788fa3e2c07..ea4843e95b01f 100644 --- a/clang/test/AST/ByteCode/cxx20.cpp +++ b/clang/test/AST/ByteCode/cxx20.cpp @@ -1201,3 +1201,13 @@ namespace NonPureVirtualCall { int main() { check(); } } + +namespace DyamicCast { + struct X { + virtual constexpr ~X() {} + }; + struct Y : X {}; + constexpr Y y; + constexpr const X *p = &y; + constexpr const Y *q = dynamic_cast<const Y*>(p); +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
