Debian Codegraph @

gcc/testsuite/g++.dg/cpp1y/constexpr-ptrsub1.C

raw
1 // PR c++/100209
2 // { dg-do compile { target c++14 } }
3
4 struct A {
5 int x = 1;
6 };
7
8 struct B : A {
9 int y = 2;
10 int z = 3;
11 int w = 4;
12 };
13
14 constexpr bool f() {
15 B b;
16 if (&b.w - &b.x != 3)
17 /* Effectively disable this test if the layout of B isn't
18 what we expect. */
19 return true;
20 const int* w = &b.w;
21 return *w-- == 4 && *w-- == 3 && *w-- == 2 && *w-- == 1;
22 }
23 static_assert(f(), "");