<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 --- - false positive, -Wsign-conversion, it is known that signed value is positive" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24037&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=6Vz5fLEY3VTqJvUF6xiJnNvavBE_WFn1WX3zi49pLpA&s=sgX6FwQvNNevKhZcJylQf5HK7U47jxjDCbu0BeOtcy4&e=">24037</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>false positive, -Wsign-conversion, it is known that signed value is positive
          </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>Example code:

#include <string>

void f(int x, std::string s) {
    if (x >= 0)
      s[x] = 'x'; // <- warning about x
}

Clang writes this false positive:

signconv.cpp:21:9: warning: implicit conversion changes signedness: 'int' to
'size_type' (aka 'unsigned long') [-Wsign-conversion]
      s[x] = 'x';
      ~ ^

it is obvious that x is positive. therefore this is a false positive. the
implicit cast is not bad.

In this code example the dangerous casts has been taken care of properly.
Adding a cast instead is the wrong solution. However adding a cast is the
recommended approach by the checker - that is the only way to fix this warning.

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.</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>