[LLVMbugs] [Bug 19724] New: -W-unused-comparison warning for overloaded operator <

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon May 12 07:19:39 PDT 2014


            Bug ID: 19724
           Summary: -W-unused-comparison warning for overloaded operator <
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: dmitry.matsypaev at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 12507
  --> http://llvm.org/bugs/attachment.cgi?id=12507&action=edit
The example of code

Here is an example of code where an unexpected warning is generated by clang
3.5 compiler. This code is also contained in the attached file.

// --------------------------- main.cpp -------------------------------

#include <iostream>
#include <cassert>

// overloaded operator
std::ostream &operator<(std::ostream &s, int const x) {
    assert(sizeof(x) == 4);
    s.write( reinterpret_cast<char const *>(&x), sizeof(x) );
    return s;

int main()

    // 1. Use operator as function
    operator < (std::cout, 4); // No warnings

    // 2. Standard usage
    std::cout < 4; // -W-unused-comparison warning is generated here

    // 3. Standard usage with pragma guard to avoid warning
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-comparison"
    std::cout < 4;// No warnings
#pragma clang diagnostic pop

    std::cout << std::endl;
    return 0;

// ------------- end of file ------------------------

After the overloading, the operator < doesn't mean the comparison any more. I'm
not sure this is the bug, but that warning seriously interrupts my work. As one
can see, I solved it like in the section #3. But I wish there is more elegant

Thank you.

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/20140512/565e1f54/attachment.html>

More information about the llvm-bugs mailing list