[LLVMbugs] [Bug 17900] New: Comparison against functions is almost always erroneous, should warn

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Nov 12 14:50:06 PST 2013


            Bug ID: 17900
           Summary: Comparison against functions is almost always
                    erroneous, should warn
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: oneill+llvmbugs at cs.hmc.edu
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Consider this code:

#include <strings.h>

int indx;

int isIndxZero()
    return index == 0;

Here the user has mistakenly written “indx” as “index“, which happens to be a
POSIX.1  function. In this comparison, index decays to a pointer-to-function,
is then compared to zero, which becomes interpreted as the null pointer

As the address of a callable function, index would *never* be null, so at the
very least, this is a comparison that is likely always false. 

It would be nice if at the very least we could warn that the comparison is
false, or better yet, warn about comparing a function with an integer.

Also, if as a result we ended up warning for &indx == 0, that'd be great too,
since that too is always false.

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/20131112/84307895/attachment.html>

More information about the llvm-bugs mailing list