@@ -1267,6 +1267,20 @@ struct FindLocalExternScope {
1267
1267
LookupResult &R;
1268
1268
bool OldFindLocalExtern;
1269
1269
};
1270
+
1271
+ // / Returns true if 'operator=' should be treated as a dependent name.
1272
+ bool isDependentAssignmentOperator (DeclarationName Name,
1273
+ DeclContext *LookupContext) {
1274
+ const auto *LookupRecord = dyn_cast_if_present<CXXRecordDecl>(LookupContext);
1275
+ // If the lookup context is the current instantiation but we are outside a
1276
+ // complete-class context, we will never find the implicitly declared
1277
+ // copy/move assignment operators because they are declared at the closing '}'
1278
+ // of the class specifier. In such cases, we treat 'operator=' like any other
1279
+ // unqualified name because the results of name lookup in the template
1280
+ // definition/instantiation context will always be the same.
1281
+ return Name.getCXXOverloadedOperator () == OO_Equal && LookupRecord &&
1282
+ !LookupRecord->isBeingDefined () && LookupRecord->isDependentContext ();
1283
+ }
1270
1284
} // end anonymous namespace
1271
1285
1272
1286
bool Sema::CppLookupName (LookupResult &R, Scope *S) {
@@ -1275,13 +1289,6 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) {
1275
1289
DeclarationName Name = R.getLookupName ();
1276
1290
Sema::LookupNameKind NameKind = R.getLookupKind ();
1277
1291
1278
- // If this is the name of an implicitly-declared special member function,
1279
- // go through the scope stack to implicitly declare
1280
- if (isImplicitlyDeclaredMemberFunctionName (Name)) {
1281
- for (Scope *PreS = S; PreS; PreS = PreS->getParent ())
1282
- if (DeclContext *DC = PreS->getEntity ())
1283
- DeclareImplicitMemberFunctionsWithName (*this , Name, R.getNameLoc (), DC);
1284
- }
1285
1292
// C++23 [temp.dep.general]p2:
1286
1293
// The component name of an unqualified-id is dependent if
1287
1294
// - it is a conversion-function-id whose conversion-type-id
@@ -1299,9 +1306,8 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) {
1299
1306
if (isImplicitlyDeclaredMemberFunctionName (Name)) {
1300
1307
for (Scope *PreS = S; PreS; PreS = PreS->getParent ())
1301
1308
if (DeclContext *DC = PreS->getEntity ()) {
1302
- if (DC->isDependentContext () && isa<CXXRecordDecl>(DC) &&
1303
- Name.getCXXOverloadedOperator () == OO_Equal &&
1304
- !R.isTemplateNameLookup ()) {
1309
+ if (!R.isTemplateNameLookup () &&
1310
+ isDependentAssignmentOperator (Name, DC)) {
1305
1311
R.setNotFoundInCurrentInstantiation ();
1306
1312
return false ;
1307
1313
}
@@ -2472,8 +2478,6 @@ bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
2472
2478
}
2473
2479
} QL (LookupCtx);
2474
2480
2475
- bool TemplateNameLookup = R.isTemplateNameLookup ();
2476
- CXXRecordDecl *LookupRec = dyn_cast<CXXRecordDecl>(LookupCtx);
2477
2481
if (!InUnqualifiedLookup && !R.isForRedeclaration ()) {
2478
2482
// C++23 [temp.dep.type]p5:
2479
2483
// A qualified name is dependent if
@@ -2486,13 +2490,14 @@ bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
2486
2490
if (DeclarationName Name = R.getLookupName ();
2487
2491
(Name.getNameKind () == DeclarationName::CXXConversionFunctionName &&
2488
2492
Name.getCXXNameType ()->isDependentType ()) ||
2489
- (Name. getCXXOverloadedOperator () == OO_Equal && LookupRec &&
2490
- LookupRec-> isDependentContext () && !TemplateNameLookup )) {
2493
+ (!R. isTemplateNameLookup () &&
2494
+ isDependentAssignmentOperator (Name, LookupCtx) )) {
2491
2495
R.setNotFoundInCurrentInstantiation ();
2492
2496
return false ;
2493
2497
}
2494
2498
}
2495
2499
2500
+ CXXRecordDecl *LookupRec = dyn_cast<CXXRecordDecl>(LookupCtx);
2496
2501
if (LookupDirect (*this , R, LookupCtx)) {
2497
2502
R.resolveKind ();
2498
2503
if (LookupRec)
@@ -2604,7 +2609,7 @@ bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
2604
2609
// template, and if the name is used as a template-name, the
2605
2610
// reference refers to the class template itself and not a
2606
2611
// specialization thereof, and is not ambiguous.
2607
- if (TemplateNameLookup )
2612
+ if (R. isTemplateNameLookup () )
2608
2613
if (auto *TD = getAsTemplateNameDecl (ND))
2609
2614
ND = TD;
2610
2615
0 commit comments