This patch just makes the error message clearer by reinforcing the cause
was a lack of viable three-way comparison function for the
complete object.
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Paths
| Differential D97990
[clang] Improve diagnostics on implicitly deleted defaulted comparisons ClosedPublic Authored by mizvekov on Mar 4 2021, 4:30 PM.
Details Summary This patch just makes the error message clearer by reinforcing the cause Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Diff Detail
Event TimelineComment Actions I don't think this change is right: for struct A { int &r; bool operator==(const A&) const = default; }; we should warn about the reference member (as we do), but for struct A { int &r; bool operator<(const A&) const = default; }; ... we shouldn't recurse to subobjects because they make no difference. The problem in that example is that there's no operator<=> for A; the fact that there's a reference member is irrelevant. I think it would be useful to change the diagnostic from <stdin>:3:8: warning: explicitly defaulted relational comparison operator is implicitly deleted [-Wdefaulted-function-deleted] bool operator<(const A &) const = default; ^ <stdin>:3:8: note: defaulted 'operator<' is implicitly deleted because there is no viable comparison function to something more verbose, such as <stdin>:3:8: warning: explicitly defaulted relational comparison operator is implicitly deleted [-Wdefaulted-function-deleted] bool operator<(const A &) const = default; ^ <stdin>:3:8: note: defaulted 'operator<' is implicitly deleted because there is no viable three-way comparison function for 'A' mizvekov retitled this revision from [clang] Always provide relevant subobject for 'no viable comparison' to [clang] Improve diagnostics on implicitly deleted defaulted comparisons.Mar 8 2021, 6:12 PM Comment ActionsYou are absolutely right, my bad!! So we stealth fix this revision to improve the message :D Comment Actions Change to simpler way to do it: rsmith added inline comments.
This revision is now accepted and ready to land.Mar 12 2021, 1:48 PM
Closed by commit rGc9fd92d57398: [clang] Improve diagnostics on implicitly deleted defaulted comparisons (authored by mizvekov). · Explain WhyMar 12 2021, 4:14 PM This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 329289 clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
clang/test/CXX/class/class.compare/class.eq/p2.cpp
clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
|
Would it be useful to apply the same diagnostic improvement to this diagnostic too? (Genuine question: I *think* we'll attach a note pointing to the deleted function in this case, which would probably make the "for T" part just be noise, but I've not checked.)