<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 --- - Inaccurate warning message with -Wabsolute-value"
   href="https://llvm.org/bugs/show_bug.cgi?id=25325">25325</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Inaccurate warning message with -Wabsolute-value
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </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>Yunzhong_Gao@playstation.sony.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, rtrieu@google.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.]</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>