<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 --- - -Wunused-comparison fires on overloaded comparision operators regardless of return type"
href="http://llvm.org/bugs/show_bug.cgi?id=19791">19791</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>-Wunused-comparison fires on overloaded comparision operators regardless of return type
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.4
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>seth.cantrell@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>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
warns:
struct S {
void operator != (int) {}
};
int main() {
S s;
s != 1; // warning: inequality comparison result unused
[-Wunused-comparison]
}
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
type.
(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. ;)</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>