[llvm-bugs] [Bug 42243] New: incorrect reinterpret_cast from integer to pointer error on invalid constexpr initialization
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Jun 11 19:36:05 PDT 2019
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: unassignedclangbugs at nondot.org
Reporter: zhonghao at pku.org.cn
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
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190612/f04f7046/attachment.html>
More information about the llvm-bugs
mailing list