[PATCH] D59103: [clang-tidy] New checker bugprone-incomplete-comparison-operator

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 7 13:31:37 PST 2019


aaron.ballman added a comment.

I'm definitely worried about the false positive rate for this check -- from a quick look at the diagnostics from LLVM, every one of them is a false positive (though perhaps I've missed something; it was a very quick look). Requiring users to explicitly use a declaration within the operator seems like it could get onerous for complex classes that support the notion of equality from a few members as opposed to all members.

Also, can you add some tests for classes that inherit members, perhaps even private ones? e.g.,

  struct Base {
    int Member;
  };
  
  struct Derived : Base {
    int OtherMember;
  
    bool operator==(const Derived &RHS) const { return OtherMember == RHS.OtherMember; }
  };
  
  struct Derived2 : private Base {
    int OtherMember;
  
    bool operator==(const Derived2 &RHS) const { return OtherMember == RHS.OtherMember; }
  };

Another good test is for scenarios where you cannot compare all of the members, such as:

  struct Interesting {
    bool operator==(const Interesting &Other) const = delete;
  };
  
  struct S {
    int Member;
    Interesting OtherMember;
  
    bool operator==(const S &Other) const { return Member == Other.Member; }
  };


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D59103





More information about the cfe-commits mailing list