<html>
    <head>
      <base href="https://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 --- - sign-compare warning for == and != are pretty useless" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24036&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=rDG3YZVqWO_rliD2DPoaZX85yHO-gjXFefVPmAaYLho&s=nBQKw9X_SojUgnX9ho4m-5HMzvztN25cdpyPo6YFgLM&e=">24036</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>sign-compare warning for == and != are pretty useless
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </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>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>daniel.marjamaki@evidente.se
          </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 recommend that -Wsign-compare is not written for == and != comparisons.

For relational comparisons the sign makes a direct difference, the result of 'a
<span class="quote">> b' can be different if you do a sign-cast of an operand.</span >

For equality comparisons the sign does not make a direct difference. the result
of 'a == b' is the same even if you sign-cast an operand.

Code example:

void f(signed int a, unsigned int b) {
  if (a == b) {}
}

Clang writes this warning:

signcompare.c:3:9: warning: comparison of integers of different signs: 'int'
and 'unsigned int' [-Wsign-compare]
  if (a == b) {}
      ~ ^  ~

In my humble opinion the risk of a bug here is really low.

The proper fix for this is to write:

  if (a >= 0 && a == b) {}

However I have seen that this is fixed by a useless cast. 

This kind of false positive is indirectly a security problem. People routinely
hide these false positives using casts or changed variable types etc. and that
cause bugs and hides other real warnings.

I believe this bug report is related to:
<a class="bz_bug_link 
          bz_status_NEW " title="NEW --- - false positive, -Wsign-compare, signed value obviously can't be negative" href="show_bug.cgi?id=24035">https://llvm.org/bugs/show_bug.cgi?id=24035</a></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>