massberg created this revision. massberg added a reviewer: usaxena95. Herald added a project: All. massberg requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This fixes #62880 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D151200 Files: clang/lib/Sema/SemaDeclCXX.cpp clang/test/CXX/class/class.compare/class.compare.default/p1.cpp 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 @@ -27,6 +27,14 @@ bool operator==(const A&) const = default; // expected-error {{comparison operator template cannot be defaulted}} }; +template<class C> struct D { + C i; + friend bool operator==(const D&, D) = default; // expected-error {{must have the same type}} + friend bool operator>(D, const D&) = default; // expected-error {{must have the same type}} + friend bool operator<(const D&, const D&) = default; + friend bool operator<=(D, D) = default; +}; + template<typename T> struct Dependent { using U = typename T::type; bool operator==(U) const = default; // expected-error {{found 'U'}} Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -8626,8 +8626,7 @@ const ParmVarDecl *KnownParm = nullptr; for (const ParmVarDecl *Param : FD->parameters()) { QualType ParmTy = Param->getType(); - if (ParmTy->isDependentType()) - continue; + if (!KnownParm) { auto CTy = ParmTy; // Is it `T const &`? @@ -8656,6 +8655,8 @@ if (Ok) { KnownParm = Param; } else { + if (ParmTy->isDependentType()) + continue; // Don't diagnose an implicit 'operator=='; we will have diagnosed the // corresponding defaulted 'operator<=>' already. if (!FD->isImplicit()) { @@ -8675,7 +8676,8 @@ } return true; } - } else if (!Context.hasSameType(KnownParm->getType(), ParmTy)) { + } + if (KnownParm && !Context.hasSameType(KnownParm->getType(), ParmTy)) { Diag(FD->getLocation(), diag::err_defaulted_comparison_param_mismatch) << int(DCK) << KnownParm->getType() << KnownParm->getSourceRange() << ParmTy << Param->getSourceRange();
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 @@ -27,6 +27,14 @@ bool operator==(const A&) const = default; // expected-error {{comparison operator template cannot be defaulted}} }; +template<class C> struct D { + C i; + friend bool operator==(const D&, D) = default; // expected-error {{must have the same type}} + friend bool operator>(D, const D&) = default; // expected-error {{must have the same type}} + friend bool operator<(const D&, const D&) = default; + friend bool operator<=(D, D) = default; +}; + template<typename T> struct Dependent { using U = typename T::type; bool operator==(U) const = default; // expected-error {{found 'U'}} Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -8626,8 +8626,7 @@ const ParmVarDecl *KnownParm = nullptr; for (const ParmVarDecl *Param : FD->parameters()) { QualType ParmTy = Param->getType(); - if (ParmTy->isDependentType()) - continue; + if (!KnownParm) { auto CTy = ParmTy; // Is it `T const &`? @@ -8656,6 +8655,8 @@ if (Ok) { KnownParm = Param; } else { + if (ParmTy->isDependentType()) + continue; // Don't diagnose an implicit 'operator=='; we will have diagnosed the // corresponding defaulted 'operator<=>' already. if (!FD->isImplicit()) { @@ -8675,7 +8676,8 @@ } return true; } - } else if (!Context.hasSameType(KnownParm->getType(), ParmTy)) { + } + if (KnownParm && !Context.hasSameType(KnownParm->getType(), ParmTy)) { Diag(FD->getLocation(), diag::err_defaulted_comparison_param_mismatch) << int(DCK) << KnownParm->getType() << KnownParm->getSourceRange() << ParmTy << Param->getSourceRange();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits