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

            Bug ID: 42243
           Summary: incorrect reinterpret_cast from integer to pointer
                    error on invalid constexpr initialization
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangb...@nondot.org
          Reporter: zhong...@pku.org.cn
                CC: blitzrak...@gmail.com, dgre...@apple.com,
                    erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
                    richard-l...@metafoo.co.uk

My clang is 9.0.0, and the code is:

struct S { int a, b[1]; };

constexpr S *p1 = (S*)0;
constexpr int *q1 = p1->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. A
related code is as follow:

struct S { int a, b; } s;

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

clang accepts both samples.
gcc reject them:

source>:4:25: error: dereferencing a null pointer in '*(S*)p1'

    4 | constexpr int *q1 = p1->b;

      |                         ^

Compiler returned: 1

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to