<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - -W-unused-comparison warning for overloaded operator <"
href="http://llvm.org/bugs/show_bug.cgi?id=19724">19724</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>-W-unused-comparison warning for overloaded operator <
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dmitry.matsypaev@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=12507" name="attach_12507" title="The example of code">attachment 12507</a> <a href="attachment.cgi?id=12507&action=edit" title="The example of code">[details]</a></span>
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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>