Skip to content

Commit f91df0d

Browse files
authored
[clang][bytecode] Diagnose failed MemberPtrPtr casts differently (#136407)
Return Invalid() here instead of just false to match the diagnostic output of the current interpreter.
1 parent c47042c commit f91df0d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

clang/lib/AST/ByteCode/Interp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1932,7 +1932,7 @@ inline bool CastMemberPtrPtr(InterpState &S, CodePtr OpPC) {
19321932
S.Stk.push<Pointer>(*Ptr);
19331933
return true;
19341934
}
1935-
return false;
1935+
return Invalid(S, OpPC);
19361936
}
19371937

19381938
//===----------------------------------------------------------------------===//

clang/test/AST/ByteCode/memberpointers.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,21 @@ namespace CallExprTypeMismatch {
249249
}
250250
static_assert(test(), "");
251251
}
252+
253+
namespace CastMemberPtrPtrFailed{
254+
struct S {
255+
constexpr S() {}
256+
constexpr int f() const;
257+
constexpr int g() const;
258+
};
259+
struct T : S {
260+
constexpr T(int n) : S(), n(n) {}
261+
int n;
262+
};
263+
264+
constexpr int S::g() const {
265+
return this->*(int(S::*))&T::n; // both-note {{subexpression}}
266+
}
267+
static_assert(S().g(), ""); // both-error {{constant expression}} \
268+
// both-note {{in call to 'S().g()'}}
269+
}

0 commit comments

Comments
 (0)