[clang] [clang][bytecode] Don't outright reject dyamic casts (PR #167517)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 11 07:03:48 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
Just delegate to the subexpr instead.
---
Full diff: https://github.com/llvm/llvm-project/pull/167517.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+5)
- (modified) clang/test/AST/ByteCode/cxx20.cpp (+10)
``````````diff
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);
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/167517
More information about the cfe-commits
mailing list