https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68711

            Bug ID: 68711
           Summary: [5 regression] SEGV on an invalid offsetof of a member
                    of a virtual base
           Product: gcc
           Version: 6.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: ---

Current trunk (6.0.0 20151205) silently accepts the invalid program below which
then crashes at runtime.  This was observed on x86_64.

$ cat x.cpp && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -Wall
-xc++ x.cpp && ./a.out

struct A { int i; };

struct B: virtual A { };

int main ()
{
    return __builtin_offsetof (B, i);
}
Segmentation fault (core dumped)

GCC 5.1 and Clang reject the program with an error similar to the one below. 
So does GCC 6.0.0 20151125 on powerpc64le.  I haven't yet looked to see if it's
a recent problem or if it's target-specific.

$ ~/bin/gcc-5.1.0/bin/g++ x.cppx.cpp: In function ‘int main()’:
x.cpp:9:35: error: invalid access to non-static data member ‘A::i’ in virtual
base of NULL object
     return __builtin_offsetof (B, i);
                                   ^

Reply via email to