This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/71188] New: missing warning converting __builtin_offsetof and sizeof to pointer
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 18 May 2016 23:43:31 +0000
- Subject: [Bug c/71188] New: missing warning converting __builtin_offsetof and sizeof to pointer
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71188
Bug ID: 71188
Summary: missing warning converting __builtin_offsetof and
sizeof to pointer
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
I would expect the following test case to elicit at least three warnings, one
for each of the initializations. GCC seems to treat the __builtin_offsetof and
sizeof result and as a literal zero and doesn't give a warning. (Clang gives a
-Wnon-literal-null-conversion warning for the first two and a -Wint-conversion
for the last one).
$ cat u.cpp && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -S
-Wall -Wextra -Wpedantic -xc u.cpp
struct S { int i; };
int a [0];
int *p = __builtin_offsetof (struct S, i);
int *q = sizeof a;
int *r = (char*)&((struct S*)0)->i - (char*)((struct S*)0);
u.cpp:3:5: warning: ISO C forbids zero-size array âaâ [-Wpedantic]
int a [0];
^
u.cpp:7:10: warning: initialization makes pointer from integer without a cast
[-Wint-conversion]
int *r = (char*)&((struct S*)0)->i - (char*)((struct S*)0);
^