[clang] [Clang][Sema] Correctly transform dependent operands of overloaded binary operator& (PR #97596)
Krystian Stasiowski via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 3 09:15:59 PDT 2024
https://github.com/sdkrystian updated https://github.com/llvm/llvm-project/pull/97596
>From d041273f56d59c9f466a9bb9a60b7501daa4844f Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski <sdkrystian at gmail.com>
Date: Wed, 3 Jul 2024 10:47:23 -0400
Subject: [PATCH 1/2] [Clang][Sema] Correctly transform dependent operands of
overloaded binary operator&
---
clang/lib/Sema/TreeTransform.h | 2 +-
.../expr.prim.id/expr.prim.id.general/p4.cpp | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
create mode 100644 clang/test/CXX/expr/expr.prim/expr.prim.id/expr.prim.id.general/p4.cpp
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 51ba22f99e3a3..4450ebaf615cd 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -12919,7 +12919,7 @@ TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
}
ExprResult First;
- if (E->getOperator() == OO_Amp)
+ if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp)
First = getDerived().TransformAddressOfOperand(E->getArg(0));
else
First = getDerived().TransformExpr(E->getArg(0));
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.id/expr.prim.id.general/p4.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.id/expr.prim.id.general/p4.cpp
new file mode 100644
index 0000000000000..e6d9c171e3893
--- /dev/null
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.id/expr.prim.id.general/p4.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -verify %s
+
+struct A {
+ int x;
+};
+
+void operator&(A, A);
+
+template<typename T>
+struct B {
+ int f() {
+ return T::x & 1; // expected-error {{invalid use of non-static data member 'x'}}
+ }
+};
+
+template struct B<A>; // expected-note {{in instantiation of}}
>From 9627cd91d996b3d0b13f85b6f683ca48e2d5edd7 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski <sdkrystian at gmail.com>
Date: Wed, 3 Jul 2024 12:15:48 -0400
Subject: [PATCH 2/2] [FOLD] add release note
---
clang/docs/ReleaseNotes.rst | 2 ++
1 file changed, 2 insertions(+)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 181d10008bc8c..c06f5a8d4b6e1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -965,6 +965,8 @@ Bug Fixes to C++ Support
forward-declared class. (#GH93512).
- Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788).
- Fixed an assertion failure about invalid conversion when calling lambda. (#GH96205).
+- Fixed a bug where the first operand of binary ``operator&`` would be transformed as if it was the operand
+ of the address of operator. (#GH97483).
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
More information about the cfe-commits
mailing list