[clang] [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (PR #91498)

Krystian Stasiowski via cfe-commits cfe-commits at lists.llvm.org
Wed May 8 12:56:14 PDT 2024


================
@@ -1269,19 +1269,19 @@ struct FindLocalExternScope {
 };
 } // end anonymous namespace
 
+static bool isDependentAssignmentOperator(DeclarationName Name,
+                                          DeclContext *LookupContext) {
+  auto *LookupRecord = dyn_cast_if_present<CXXRecordDecl>(LookupContext);
+  return Name.getCXXOverloadedOperator() == OO_Equal && LookupRecord &&
+         !LookupRecord->isBeingDefined() && LookupRecord->isDependentContext();
----------------
sdkrystian wrote:

The reason `operator=` is dependent when the current class is a templated entity is because each specialization declares its own set of special member functions, and according to [[special] p1](http://eel.is/c++draft/special#1.sentence-4), they are "declared at the closing `}` of the _class-specifier_". When instantiating a templated class, they are declared after all other member declarations are instantiated.

If the lookup context is the current instantiation and the current instantiation is incomplete (e.g. because `operator=` is named outside a complete-class context), we will never find the implicitly declared copy/move assignment operators because they are always declared last (neither in the template definition context, nor in the template instantiation context). So, we just treat it like any other unqualified name during lookup.

https://github.com/llvm/llvm-project/pull/91498


More information about the cfe-commits mailing list