Debian Codegraph @

gcc/testsuite/g++.dg/abi/offsetof.C

raw
1 // Test that we can refer to the address of a base member of a null pointer
2 // to get its offset. The standard says that offsetof shall not be used on
3 // non-POD classes, but there seems to be no such restriction on the common
4 // implementation thereof.
5
6 // Yes, this is bad, naughty, evil code. But it seems to be well-formed.
7
8 // { dg-do run }
9
10 struct A { int i; };
11
12 struct B: public A {
13 virtual void f ();
14 };
15
16 struct C: public B { };
17
18 int main ()
19 {
20 return ((__SIZE_TYPE__) &((C*)0)->i) != sizeof(void*);
21 }