[PATCH] D151200: [Clang][C++20] Error out if parameter types of a defaulted comparison operator aren't as expected.
Jens Massberg via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 24 01:03:20 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc3c0774b1d6e: [Clang][C++20] Error out if parameter types of a defaulted comparion operator… (authored by massberg).
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.525051.patch
Type: text/x-patch
Size: 1495 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230524/4c55648b/attachment.bin>
More information about the cfe-commits
mailing list