[clang] [clang][bytecode] Check memberpointer exprs for errors (PR #185370)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 9 01:05:54 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/185370.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+7)
- (modified) clang/test/AST/ByteCode/memberpointers.cpp (+13-2)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 6d8b84a83a4ad..65794637b03be 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -269,6 +269,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
}
case CK_DerivedToBaseMemberPointer: {
+ if (CE->containsErrors())
+ return false;
assert(classifyPrim(CE) == PT_MemberPtr);
assert(classifyPrim(SubExpr) == PT_MemberPtr);
@@ -291,6 +293,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
}
case CK_BaseToDerivedMemberPointer: {
+ if (CE->containsErrors())
+ return false;
assert(classifyPrim(CE) == PT_MemberPtr);
assert(classifyPrim(SubExpr) == PT_MemberPtr);
@@ -1076,6 +1080,9 @@ bool Compiler<Emitter>::VisitParenExpr(const ParenExpr *E) {
template <class Emitter>
bool Compiler<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
+ if (BO->containsErrors())
+ return false;
+
// Need short-circuiting for these.
if (BO->isLogicalOp() && !BO->getType()->isVectorType())
return this->VisitLogicalBinOp(BO);
diff --git a/clang/test/AST/ByteCode/memberpointers.cpp b/clang/test/AST/ByteCode/memberpointers.cpp
index fb489a1961434..e2a154914c83b 100644
--- a/clang/test/AST/ByteCode/memberpointers.cpp
+++ b/clang/test/AST/ByteCode/memberpointers.cpp
@@ -1,7 +1,7 @@
// RUN: %clang_cc1 -std=c++14 -fexperimental-new-constant-interpreter -verify=expected,both %s
// RUN: %clang_cc1 -std=c++23 -fexperimental-new-constant-interpreter -verify=expected,both %s
-// RUN: %clang_cc1 -std=c++14 -verify=ref,both %s
-// RUN: %clang_cc1 -std=c++23 -verify=ref,both %s
+// RUN: %clang_cc1 -std=c++14 -verify=ref,both %s
+// RUN: %clang_cc1 -std=c++23 -verify=ref,both %s
namespace MemberPointers {
struct A {
@@ -303,3 +303,14 @@ namespace Equality {
constexpr int (T<17>::*deepm) = (int(T<10>::*))&T<30>::m;
static_assert(deepm == &T<50>::m, "");
}
+
+namespace Errors {
+#if __cplusplus >= 202302L
+ constexpr bool test1() {
+ X s; // both-error {{unknown type name}}
+ s.*bar(); // both-error {{use of undeclared identifier}}
+ return true;
+ }
+ static_assert(test1(), ""); // both-error {{not an integral constant expression}}
+#endif
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/185370
More information about the cfe-commits
mailing list