[llvm-bugs] [Bug 25325] New: Inaccurate warning message with -Wabsolute-value
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Oct 26 16:08:10 PDT 2015
https://llvm.org/bugs/show_bug.cgi?id=25325
Bug ID: 25325
Summary: Inaccurate warning message with -Wabsolute-value
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: Yunzhong_Gao at playstation.sony.com
CC: llvm-bugs at lists.llvm.org, rtrieu at google.com
Classification: Unclassified
Hi,
We encounter this issue during internal documentation review.
// test.cpp
#include <cstdlib>
#include <cstdio>
int foo(unsigned u) { return abs(u); }
int main() {
printf("%d\n", foo(0xFFFFFFFFu)); // abs(0xffffffff) => abs(-1) => 1
return 0;
}
// warning: taking the absolute value of unsigned type 'unsigned int' has no
// effect [-Wabsolute-value]
This is a useful warning message, but in this case, it is not accurate to say
that the abs() call has no effect.
On the other hand, in many cases the abs() does indeed have no effect, like
below, so I find it tricky to come up with a warning message that covers all
cases. I am hoping that someone else is able to suggest a better warning
message.
e.g. in the following two cases, abs() and labs() have no effect:
int f1(unsigned short x) { return abs(x); }
long f2(unsigned x) { return labs(x); }
Some alternative texts that we have internally discussed:
(a)
warning: taking the absolute value of unsigned type 'unsigned int' may have an
unintended effect.
[But, it sounds vague if we do not describe what is the unintended effect.]
(b)
warning: taking the absolute value of unsigned type 'unsigned int' has an
effect such that an unsigned number gets implicitly converted to its
corresponding signed integral type before its absolute value is taken. This
conversion could turn a large unsigned number into a negative number.
[But, it sounds verbose and does not mention the "no effect" case.]
--
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/20151026/35f51a74/attachment-0001.html>
More information about the llvm-bugs
mailing list