[PATCH] D97990: [clang] Always provide relevant subobject for 'no viable comparison'

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 8 12:54:24 PST 2021


rsmith added a comment.

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'


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97990



More information about the cfe-commits mailing list