Add -Wabsolute-value, warnings about absolute value functions.

Press ? to show keyboard shortcuts.
Committed
rtrieuFeb 25 2014, 5:17 PM
Parents
rL202210: Simplify base64 routine a bit.
Branches
Unknown
Tags
Unknown
Subscribers
None
Description

Add -Wabsolute-value, warnings about absolute value functions.

The warnings fall into three groups.

  1. Using an absolute value function of the wrong type, for instance, using the

int absolute value function when the argument is a floating point type.
2) Using the improper sized absolute value function, for instance, using abs
when the argument is a long long. llabs should be used instead.

From these two cases, an implicit conversion will occur which may cause
unexpected behavior. Where possible, suggest the proper absolute value
function to use, and which header to include if the function is not available.

3) Taking the absolute value of an unsigned value. In addition to this warning,
suggest to remove the function call. This usually indicates a logic error
since the programmer assumed negative values would have been possible.

rL202211

cfe/trunk/include/clang/Basic/DiagnosticGroups.td

Loading...

cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td

Loading...

cfe/trunk/include/clang/Sema/Sema.h

Loading...

cfe/trunk/lib/Sema/SemaChecking.cpp

Loading...

cfe/trunk/test/Sema/warn-absolute-value-header.c

Loading...

cfe/trunk/test/Sema/warn-absolute-value.c

Loading...

cfe/trunk/test/SemaCXX/warn-absolute-value-header.cpp

Loading...

Add Comment