https://llvm.org/bugs/show_bug.cgi?id=24036
Bug ID: 24036
Summary: sign-compare warning for == and != are pretty useless
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Frontend
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
Classification: Unclassified
I recommend that -Wsign-compare is not written for == and != comparisons.
For relational comparisons the sign makes a direct difference, the result of 'a
> b' can be different if you do a sign-cast of an operand.
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:
https://llvm.org/bugs/show_bug.cgi?id=24035
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs