[clang] [clang][bytecode] Fix discarded addrof operators... (PR #180534)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 9 06:54:43 PST 2026
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/180534
>From ef28197eafb82794b6b5d9872d9f671391efb5d2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 9 Feb 2026 15:45:29 +0100
Subject: [PATCH] [clang][bytecode] Fix discardded addrof operators...
... of member pointers.
---
clang/lib/AST/ByteCode/Compiler.cpp | 2 ++
clang/test/AST/ByteCode/memberpointers.cpp | 9 +++++++++
2 files changed, 11 insertions(+)
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..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