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);
       }


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);
       }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D147782: ... Jonathan Camilleri via Phabricator via cfe-commits

Reply via email to