[llvm-bugs] [Bug 28682] New: No warning when comparing zero-valued enum with a pointer

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Jul 24 03:32:55 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=28682

            Bug ID: 28682
           Summary: No warning when comparing zero-valued enum with a
                    pointer
           Product: clang
           Version: 3.8
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: martin.thomson at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

This C program produces a warning:

typedef enum { z = 0, nz = 1 } e;
int main() {
  void *p = (void *)main; /* value doesn't matter */
  return p == nz;
}


$ cc -Werror -Weverything -o main main.c
main.c:7:12: error: comparison between pointer and integer ('void *' and 'int')
[-Werror]
  return p == nz;
         ~ ^  ~~

Change the line to `p == z` and it builds without complaint.

Comparing a pointer to an enum is completely braindead and it should - at the
very least - elicit a warning.  (I did this myself and only found the error at
runtime.)

--
clang++ identifies this as a problem, but probably only because pointer types
in C++ are more distinctly defined:

$ clang++ -Weverything -o main main.c
... whining about my cast ...
main.c:7:12: error: comparison between pointer and integer ('void *' and 'int')
  return p == z;
         ~ ^  ~

-- 
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/20160724/cdea16f4/attachment-0001.html>


More information about the llvm-bugs mailing list