[llvm-bugs] [Bug 40725] New: some problematic casts applied to NULL are not diagnosed

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Feb 13 16:28:59 PST 2019


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

            Bug ID: 40725
           Summary: some problematic casts applied to NULL are not
                    diagnosed
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: richard-llvm at metafoo.co.uk
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Testcase:

#define NULL __null

int *p = reinterpret_cast<int*>(NULL); // #1
enum E {}; E e = static_cast<E>(NULL); // #2
float f = static_cast<float>(NULL); // #3

This produces no diagnostics. All marked lines should result in a warning:

 -- #1 does not necessarily produce a null pointer; it produces a pointer whose
value is all-zero-bits. We should suggest replacing reinterpret_cast with
static_cast here.
 -- #2 and #3 don't make any sense; they're using NULL as an integer rather
than as a pointer. We should suggest replacing NULL with 0 here.

Generally, we should probably warn on any use of NULL where nullptr would not
be valid or would mean something else.

-- 
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/20190214/cb7b3653/attachment.html>


More information about the llvm-bugs mailing list