[PATCH] D103850: [clang] diagnose instead of assert for defaulted comparison return type deduction.

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 16 10:39:27 PDT 2021


rsmith added inline comments.


================
Comment at: clang/test/CXX/class/class.compare/class.spaceship/p2.cpp:200
+  struct b3 {
+    auto operator<=>(b3 const &) const = default; // expected-error {{cannot be deduced because three-way comparison for member 'f' would compare as builtin type 'void (*)()' which is not currently supported}}
+    // expected-warning at -1 {{implicitly deleted}}
----------------
I think three-way comparison for function pointers is ill-formed, and that the problem in this case is that [over.built] lists candidates for which a three-way comparison is invalid. So our overload resolution succeeds, but results in a meaningless builtin candidate with an undefined return type.

I think the behavior here after this patch is fine -- we should treat the comparison as deleted -- but the diagnostic is wrong. This isn't a "not currently supported" case, this is a "not a valid expression" case, per [class.compare.default]/3.2 (except that the wording currently gets this wrong and doesn't actually say what happens here, because we're actually in [class.compare.default]/3.1). Though perhaps the better fix would be to not even include a builtin candidate for `operator<=>(void (*)(), void (*)())`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103850/new/

https://reviews.llvm.org/D103850



More information about the cfe-commits mailing list