[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 07:25:36 PDT 2023
massberg updated this revision to Diff 524704.
massberg added a comment.
Also error out if the comparion operator has a single parameter that isn't a const reference. See also https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2002r1.html on how it shpuld behave in C++20.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D151200/new/
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,16 @@
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'}}
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 &`?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151200.524704.patch
Type: text/x-patch
Size: 1495 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230523/8d4204b9/attachment-0001.bin>
More information about the cfe-commits
mailing list