[clang] [clang][bytecode] Diagnose regular CK_LValueBitCast cast nodes (PR #175721)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 12 23:48:21 PST 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/175721
We already do this similarly for CXXReinterpretCastExprs, except in that case we try harder to make things work.
>From bb4dc96c6193eaa09d226bff61e78af4d6e10eea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Tue, 13 Jan 2026 08:44:11 +0100
Subject: [PATCH] [clang][bytecode] Diagnose regular CK_LValueBitCast cast
nodes
We already do this similarly for CXXReinterpretCastExprs, except in that
case we try harder to make things work.
---
clang/lib/AST/ByteCode/Compiler.cpp | 3 +++
clang/test/AST/ByteCode/cxx11.cpp | 4 ++++
2 files changed, 7 insertions(+)
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;
};
More information about the cfe-commits
mailing list