Skip to content

Commit d853c33

Browse files
committed
[Clang][Sema] Partially revert changes to operator= from #90152
1 parent eb65b73 commit d853c33

File tree

4 files changed

+40
-20
lines changed

4 files changed

+40
-20
lines changed

clang/lib/Sema/SemaExprMember.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,10 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
996996
// build a CXXDependentScopeMemberExpr.
997997
if (R.wasNotFoundInCurrentInstantiation() ||
998998
(IsArrow && !BaseExprType->isPointerType() &&
999-
BaseExprType->isDependentType()))
999+
BaseExprType->isDependentType()) ||
1000+
(R.getLookupName().getCXXOverloadedOperator() == OO_Equal &&
1001+
(SS.isSet() ? SS.getScopeRep()->isDependent()
1002+
: BaseExprType->isDependentType())))
10001003
return ActOnDependentMemberExpr(BaseExpr, BaseExprType, IsArrow, OpLoc, SS,
10011004
TemplateKWLoc, FirstQualifierInScope,
10021005
R.getLookupNameInfo(), TemplateArgs);

clang/lib/Sema/SemaLookup.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,7 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) {
12821282
if (DeclContext *DC = PreS->getEntity())
12831283
DeclareImplicitMemberFunctionsWithName(*this, Name, R.getNameLoc(), DC);
12841284
}
1285+
12851286
// C++23 [temp.dep.general]p2:
12861287
// The component name of an unqualified-id is dependent if
12871288
// - it is a conversion-function-id whose conversion-type-id
@@ -1294,20 +1295,6 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) {
12941295
return false;
12951296
}
12961297

1297-
// If this is the name of an implicitly-declared special member function,
1298-
// go through the scope stack to implicitly declare
1299-
if (isImplicitlyDeclaredMemberFunctionName(Name)) {
1300-
for (Scope *PreS = S; PreS; PreS = PreS->getParent())
1301-
if (DeclContext *DC = PreS->getEntity()) {
1302-
if (DC->isDependentContext() && isa<CXXRecordDecl>(DC) &&
1303-
Name.getCXXOverloadedOperator() == OO_Equal) {
1304-
R.setNotFoundInCurrentInstantiation();
1305-
return false;
1306-
}
1307-
DeclareImplicitMemberFunctionsWithName(*this, Name, R.getNameLoc(), DC);
1308-
}
1309-
}
1310-
13111298
// Implicitly declare member functions with the name we're looking for, if in
13121299
// fact we are in a scope where it matters.
13131300

@@ -2485,10 +2472,8 @@ bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
24852472
// is operator=, or
24862473
// - [...]
24872474
if (DeclarationName Name = R.getLookupName();
2488-
(Name.getNameKind() == DeclarationName::CXXConversionFunctionName &&
2489-
Name.getCXXNameType()->isDependentType()) ||
2490-
(Name.getCXXOverloadedOperator() == OO_Equal && LookupRec &&
2491-
LookupRec->isDependentContext())) {
2475+
Name.getNameKind() == DeclarationName::CXXConversionFunctionName &&
2476+
Name.getCXXNameType()->isDependentType()) {
24922477
R.setNotFoundInCurrentInstantiation();
24932478
return false;
24942479
}

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,8 @@ Sema::ActOnDependentIdExpression(const CXXScopeSpec &SS,
750750
if (!MightBeCxx11UnevalField && !isAddressOfOperand && !IsEnum &&
751751
isa<CXXMethodDecl>(DC) &&
752752
cast<CXXMethodDecl>(DC)->isImplicitObjectMemberFunction()) {
753-
QualType ThisType = cast<CXXMethodDecl>(DC)->getThisType().getNonReferenceType();
753+
QualType ThisType =
754+
cast<CXXMethodDecl>(DC)->getThisType().getNonReferenceType();
754755

755756
// Since the 'this' expression is synthesized, we don't need to
756757
// perform the double-lookup check.

clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,36 @@ namespace N3 {
453453
this->A::operator=(*this);
454454
}
455455
};
456+
457+
template<typename T>
458+
struct C {
459+
template<typename U>
460+
void operator=(int);
461+
462+
void not_instantiated() {
463+
operator=<int>(0);
464+
C::operator=<int>(0);
465+
this->operator=<int>(0);
466+
this->C::operator=<int>(0);
467+
468+
operator=(*this);
469+
C::operator=(*this);
470+
this->operator=(*this);
471+
this->C::operator=(*this);
472+
}
473+
};
474+
475+
template<typename T>
476+
struct D {
477+
auto not_instantiated() -> decltype(operator=(0)); // expected-error {{use of undeclared 'operator='}}
478+
};
479+
480+
template<typename T>
481+
struct E {
482+
auto instantiated(E& e) -> decltype(operator=(e)); // expected-error {{use of undeclared 'operator='}}
483+
};
484+
485+
template struct E<int>; // expected-note {{in instantiation of template class 'N3::E<int>' requested here}}
456486
} // namespace N3
457487

458488
namespace N4 {
@@ -520,4 +550,5 @@ namespace N4 {
520550
};
521551

522552
template void D<B>::instantiated(D); // expected-note {{in instantiation of}}
553+
523554
} // namespace N4

0 commit comments

Comments
 (0)