[LLVMbugs] [Bug 19791] New: -Wunused-comparison fires on overloaded comparision operators regardless of return type

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon May 19 09:32:32 PDT 2014


            Bug ID: 19791
           Summary: -Wunused-comparison fires on overloaded comparision
                    operators regardless of return type
           Product: clang
           Version: 3.4
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: seth.cantrell at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I have a codebase where operator != and other comparision operators are being
abused somewhat to perform side effecting operations on a class. Since the
intent is the side-effect and not the result the result is generally unused,
causing -Wunused-comparison to fire. In other cases this is a useful warning so
I don't want to turn it off.

The abuse is something like this:

    struct S {
      array<bool, MAX_INDEX> arr;

      S &operator != (int i) {
        arr.at(i) = false;
        return *this;
      S &operator = (int i) {
        arr.at(i) = true;
        returh *this;

Although I'm pursuing changes to the codebase to remove the issue, I've noticed
that even if operator != is declared to return void -Wunused-comparison still

    struct S {
      void operator != (int) {}

    int main() {
      S s;
      s != 1; // warning: inequality comparison result unused

It seems not unreasonable that this warning would require the type to be
non-void in order to trigger, and perhaps even require it to be a non-reference

(And maybe there should be another warning -Woperator-overloading-abuse that
would trigger when the return type of operator != _is_ void or a reference
type. ;)

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140519/32ae1c27/attachment.html>

More information about the llvm-bugs mailing list