[LLVMbugs] [Bug 24037] New: false positive, -Wsign-conversion, it is known that signed value is positive
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Mon Jul 6 02:59:31 PDT 2015
https://llvm.org/bugs/show_bug.cgi?id=24037
Bug ID: 24037
Summary: false positive, -Wsign-conversion, it is known that
signed value is positive
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: daniel.marjamaki at evidente.se
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150706/f17e57d4/attachment.html>
More information about the llvm-bugs
mailing list