http://llvm.org/bugs/show_bug.cgi?id=19724
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: [email protected]
Reporter: [email protected]
CC: [email protected]
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
solution.
Thank you.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs