[clang] a1acc4a - [clang][bytecode] Fix discarded addrof operators... (#180534)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 9 21:01:02 PST 2026
Author: Timm Baeder
Date: 2026-02-10T06:00:58+01:00
New Revision: a1acc4ab9fa7bef5684d126ab0c29b035402d664
URL: https://github.com/llvm/llvm-project/commit/a1acc4ab9fa7bef5684d126ab0c29b035402d664
DIFF: https://github.com/llvm/llvm-project/commit/a1acc4ab9fa7bef5684d126ab0c29b035402d664.diff
LOG: [clang][bytecode] Fix discarded addrof operators... (#180534)
... of member pointers.
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/AST/ByteCode/memberpointers.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 07237263e2971..05941649c73be 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6865,6 +6865,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..08a95e66183f8 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(); } // both-warning {{left operand of comma operator has no effect}}
+}
More information about the cfe-commits
mailing list