[PATCH] D151200: [Clang][C++20] Error out if parameter types of a defaulted comparion operator are not all the same.
Jens Massberg via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 23 04:15:28 PDT 2023
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();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151200.524648.patch
Type: text/x-patch
Size: 2105 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230523/5386d0e0/attachment.bin>
More information about the cfe-commits
mailing list