This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/71188] New: missing warning converting __builtin_offsetof and sizeof to pointer


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);
          ^

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]