[clang] [clang][bytecode] Fix discarded addrof operators... (PR #180534)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 9 06:47:52 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
... of member pointers.
---
Full diff: https://github.com/llvm/llvm-project/pull/180534.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+2)
- (modified) clang/test/AST/ByteCode/memberpointers.cpp (+9)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index a0138c402e143..9f271f3c314dd 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6859,6 +6859,8 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
if (E->getType()->isMemberPointerType()) {
// C++11 [expr.unary.op]p3 has very strict rules on how the address of a
// member can be formed.
+ if (DiscardResult)
+ return true;
return this->emitGetMemberPtr(cast<DeclRefExpr>(SubExpr)->getDecl(), E);
}
// We should already have a pointer when we get here.
diff --git a/clang/test/AST/ByteCode/memberpointers.cpp b/clang/test/AST/ByteCode/memberpointers.cpp
index 5d622187e97f2..88666c3e38f44 100644
--- a/clang/test/AST/ByteCode/memberpointers.cpp
+++ b/clang/test/AST/ByteCode/memberpointers.cpp
@@ -267,3 +267,12 @@ namespace CastMemberPtrPtrFailed{
static_assert(S().g(), ""); // both-error {{constant expression}} \
// both-note {{in call to 'S().g()'}}
}
+
+namespace DiscardedAddrOfOperator {
+ class Foo {
+ public:
+ void bar();
+ };
+
+ void baz() { &Foo::bar, Foo(); }
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/180534
More information about the cfe-commits
mailing list