[clang] [clang][bytecode] Fix discardded addrof operators... (PR #180534)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 9 06:47:13 PST 2026


https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/180534

... of member pointers.

>From 3731461709913827512a8f7ca759821ff0fc26a9 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..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(); }
+}



More information about the cfe-commits mailing list