[clang] [clang][bytecode] Diagnose regular CK_LValueBitCast cast nodes (PR #175721)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 12 23:48:51 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
We already do this similarly for CXXReinterpretCastExprs, except in that case we try harder to make things work.
---
Full diff: https://github.com/llvm/llvm-project/pull/175721.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+3)
- (modified) clang/test/AST/ByteCode/cxx11.cpp (+4)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index b68576158decc..b39736587034d 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -779,6 +779,9 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
// a diagnostic if appropriate.
return this->delegate(SubExpr);
+ case CK_LValueBitCast:
+ return this->emitInvalidCast(CastKind::ReinterpretLike, /*Fatal=*/true, CE);
+
default:
return this->emitInvalid(CE);
}
diff --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp
index 9a61321f67a40..e1fb5948b7708 100644
--- a/clang/test/AST/ByteCode/cxx11.cpp
+++ b/clang/test/AST/ByteCode/cxx11.cpp
@@ -33,6 +33,10 @@ constexpr int b = b; // both-error {{must be initialized by a constant expressio
// both-note {{declared here}}
+ void func();
+ constexpr int (&fp4)() = (int(&)())func; // both-error {{constant expression}} \
+ // both-note {{reinterpret_cast}}
+
struct S {
int m;
};
``````````
</details>
https://github.com/llvm/llvm-project/pull/175721
More information about the cfe-commits
mailing list