[clang] c3c0774 - [Clang][C++20] Error out if parameter types of a defaulted comparion operator are not all the same.

Jens Massberg via cfe-commits cfe-commits at lists.llvm.org
Wed May 24 01:03:13 PDT 2023


Author: Jens Massberg
Date: 2023-05-24T10:02:58+02:00
New Revision: c3c0774b1d6ef524de3a25e1f13828d2f9861aad

URL: https://github.com/llvm/llvm-project/commit/c3c0774b1d6ef524de3a25e1f13828d2f9861aad
DIFF: https://github.com/llvm/llvm-project/commit/c3c0774b1d6ef524de3a25e1f13828d2f9861aad.diff

LOG: [Clang][C++20] Error out if parameter types of a defaulted comparion operator are not all the same.

This fixes #62880

Differential Revision: https://reviews.llvm.org/D151200

Added: 
    

Modified: 
    clang/lib/Sema/SemaDeclCXX.cpp
    clang/test/CXX/class/class.compare/class.compare.default/p1.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index e2a1de9ee5be2..cbe4229b05d00 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -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 &`?

diff  --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
index eadb5718780a3..e469e31e1f696 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -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'}}


        


More information about the cfe-commits mailing list