[llvm-bugs] [Bug 38201] New: incorrect reinterpret_cast from integer to pointer error on invalid constexpr initialization

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jul 17 17:55:28 PDT 2018


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

            Bug ID: 38201
           Summary: incorrect reinterpret_cast from integer to pointer
                    error on invalid constexpr initialization
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zhonghao at pku.org.cn
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

The code is as follow:

struct S { int a, b; } s;

constexpr S *p = (S*)0;
constexpr const int *q = &p->b;

The code is invalid not because of a cast (there is none) but because it
attempts to use a null pointer to form the address of a member of an object.
clang++ accepts it. I checked g++. It rejects the code:

error: dereferencing a null pointer in '*0'
 constexpr const int *q = &p->b;
                              ^

-- 
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/20180718/38d7cfeb/attachment.html>


More information about the llvm-bugs mailing list