[PATCH] D147782: [clang] Fix 'operator=' lookup in nested class

Jonathan Camilleri via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 7 04:53:21 PDT 2023


J-Camilleri created this revision.
Herald added a project: All.
J-Camilleri requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If implicitly declared 'operator=' declarations are generated before
encountering a use in a nested class, custom definitions of the operator
in the nested class are not found.

The issue occurs because when searching for the operator in the nested
class the implicitly declared functions are found in the IdResolver and
returned. The IdResolver does not contain the custom defined operator
and so it is ignored.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147782

Files:
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaCXX/nested-class-assignment-operator-overload.cpp


Index: clang/test/SemaCXX/nested-class-assignment-operator-overload.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/nested-class-assignment-operator-overload.cpp
@@ -0,0 +1,18 @@
+/// clang++ incorrectly rejected this program with the following error:
+/// "No matching member function for call to 'operator='"
+///
+/// Refer to github issue 59684
+
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+struct Outer {
+  void invokeAssign() { operator=({}); }
+
+  struct Inner {
+    Inner &operator=(int);
+    void invokeAssign(int D) { operator=(D); }
+  };
+};
+
+int main() {}
Index: clang/lib/Sema/SemaLookup.cpp
===================================================================
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -1325,7 +1325,7 @@
         } else {
           // We found something in this scope, we should not look at the
           // namespace scope
-          SearchNamespaceScope = false;
+          SearchNamespaceScope = Name.getCXXOverloadedOperator() == OO_Equal;
         }
         R.addDecl(ND);
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147782.511664.patch
Type: text/x-patch
Size: 1149 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230407/238c9d2d/attachment.bin>


More information about the cfe-commits mailing list