Skip to content

Commit

Permalink
[Clang][C++20] Error out if parameter types of a defaulted comparion …
Browse files Browse the repository at this point in the history
…operator are not all the same.

This fixes #62880

Differential Revision: https://reviews.llvm.org/D151200
  • Loading branch information
jensmassberg committed May 24, 2023
1 parent 82082b7 commit c3c0774
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8626,8 +8626,7 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *FD,
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 &`?
Expand Down
10 changes: 10 additions & 0 deletions clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ struct A {
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;

bool operator!=(D) const = default; // expected-error {{invalid parameter type for defaulted equality comparison operator}}
};

template<typename T> struct Dependent {
using U = typename T::type;
bool operator==(U) const = default; // expected-error {{found 'U'}}
Expand Down

0 comments on commit c3c0774

Please sign in to comment.