[clang] f91df0d - [clang][bytecode] Diagnose failed MemberPtrPtr casts differently (#136407)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 19 02:34:29 PDT 2025
Author: Timm Baeder
Date: 2025-04-19T11:34:25+02:00
New Revision: f91df0d58df4fcb5edcb89f204f0d22ade9a9262
URL: https://github.com/llvm/llvm-project/commit/f91df0d58df4fcb5edcb89f204f0d22ade9a9262
DIFF: https://github.com/llvm/llvm-project/commit/f91df0d58df4fcb5edcb89f204f0d22ade9a9262.diff
LOG: [clang][bytecode] Diagnose failed MemberPtrPtr casts differently (#136407)
Return Invalid() here instead of just false to match the diagnostic
output of the current interpreter.
Added:
Modified:
clang/lib/AST/ByteCode/Interp.h
clang/test/AST/ByteCode/memberpointers.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 49e2326186bf8..866d8e4bf2251 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1932,7 +1932,7 @@ inline bool CastMemberPtrPtr(InterpState &S, CodePtr OpPC) {
S.Stk.push<Pointer>(*Ptr);
return true;
}
- return false;
+ return Invalid(S, OpPC);
}
//===----------------------------------------------------------------------===//
diff --git a/clang/test/AST/ByteCode/memberpointers.cpp b/clang/test/AST/ByteCode/memberpointers.cpp
index db4a86ae03aff..5d622187e97f2 100644
--- a/clang/test/AST/ByteCode/memberpointers.cpp
+++ b/clang/test/AST/ByteCode/memberpointers.cpp
@@ -249,3 +249,21 @@ namespace CallExprTypeMismatch {
}
static_assert(test(), "");
}
+
+namespace CastMemberPtrPtrFailed{
+ struct S {
+ constexpr S() {}
+ constexpr int f() const;
+ constexpr int g() const;
+ };
+ struct T : S {
+ constexpr T(int n) : S(), n(n) {}
+ int n;
+ };
+
+ constexpr int S::g() const {
+ return this->*(int(S::*))&T::n; // both-note {{subexpression}}
+ }
+ static_assert(S().g(), ""); // both-error {{constant expression}} \
+ // both-note {{in call to 'S().g()'}}
+}
More information about the cfe-commits
mailing list