[clang][bytecode] Diagnose failed MemberPtrPtr casts differently (#136407)

Return Invalid() here instead of just false to match the diagnostic
output of the current interpreter.
This commit is contained in:
Timm Baeder
2025-04-19 11:34:25 +02:00
committed by GitHub
parent c47042c5b3
commit f91df0d58d
2 changed files with 19 additions and 1 deletions

View File

@@ -1932,7 +1932,7 @@ inline bool CastMemberPtrPtr(InterpState &S, CodePtr OpPC) {
S.Stk.push<Pointer>(*Ptr);
return true;
}
return false;
return Invalid(S, OpPC);
}
//===----------------------------------------------------------------------===//

View File

@@ -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()'}}
}