Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -8531,8 +8531,6 @@ QualType PlainTy = Context.getRecordType(RD); QualType RefTy = Context.getLValueReferenceType(PlainTy.withConst()); - if (IsMethod) - PlainTy = QualType(); Diag(FD->getLocation(), diag::err_defaulted_comparison_param) << int(DCK) << ParmTy << RefTy << int(!IsMethod) << PlainTy << Param->getSourceRange(); @@ -17266,10 +17264,13 @@ // that we've marked it as defaulted. FD->setWillHaveBody(false); - // If this is a comparison's defaulted definition within the record, do - // the checking when the record is complete. - if (DefKind.isComparison() && isa(FD->getLexicalDeclContext())) - return; + if (DefKind.isComparison()) { + // If this comparison's defaulting occurs within the definition of its + // lexical class context, we have to do the checking when complete. + if (auto const *RD = dyn_cast(FD->getLexicalDeclContext())) + if (!RD->isCompleteDefinition()) + return; + } // If this member fn was defaulted on its first declaration, we will have // already performed the checking in CheckCompletedCXXClass. Such a Index: clang/test/CXX/class/class.compare/class.compare.default/p1.cpp =================================================================== --- clang/test/CXX/class/class.compare/class.compare.default/p1.cpp +++ clang/test/CXX/class/class.compare/class.compare.default/p1.cpp @@ -115,6 +115,28 @@ } } +namespace evil1 { +template struct Bad { + // expected-error@+1{{found 'const float &'}} + bool operator==(T const &) const = default; + Bad(int = 0); +}; + +template struct Weird { + // expected-error@+1{{'float' cannot be used prior to '::'}} + bool operator==(typename T::Weird_ const &) const = default; + Weird(int = 0); +}; + +struct evil { + using Weird_ = Weird; +}; +template struct Bad; // expected-note{{evil1::Bad' requested}} +template struct Weird; // expected-note{{evil1::Weird' requested}} +template struct Weird; + +} // namespace evil1 + namespace P1946 { struct A { friend bool operator==(A &, A &); // expected-note {{would lose const qualifier}} @@ -161,5 +183,40 @@ bool operator==(e, int) = default; // expected-error{{expected class or reference to a constant class}} bool operator==(e *, int *) = default; // expected-error{{must have at least one}} - } // namespace p2085 + +namespace p2085_2 { +template struct S6 { + // expected-error@+2{{found 'const int &'}} + // expected-error@+1{{found 'const float &'}} + bool operator==(T const &) const; +}; +template bool S6::operator==(T const &) const = default; + +template struct S6; // expected-note{{S6::operator==' requested}} + +void f1() { + S6 a; + (void)(a == 0); // expected-note{{S6::operator==' requested}} +} + +template struct S7 { + // expected-error@+2{{'float' cannot be used}} + // expected-error@+1{{'int' cannot be used}} + bool operator==(typename T::S7_ const &) const; + S7(int = 0); +}; +template bool S7::operator==(typename T::S7_ const &) const = default; + +struct evil { + using S7_ = S7; +}; +template struct S7; // expected-note{{S7' requested}} + +void f2() { + S7 a; // expected-note{{S7' requested}} + S7 b; + (void)(a == 0); // expected-error{{invalid operands}} + (void)(b == 0); +} +} // namespace p2085_2