summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/torture/pr37716.C
blob: 13b98d68a4044a83baaec40091d7f000c579299d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// PR tree-optimization/37716
// { dg-do compile }

struct A
{
  struct B
  {
    int a, b, c, d;
    void *e[1];
  };
  B *d;
  inline void **f1 (int i) const
  {
    return d->e + d->c + i;
  }
};

template <typename T>
struct C
{
  struct D
  {
    void *v;
    inline T & f3 ()
    {
      return *reinterpret_cast <T *> (this);
    }
  };
  union
  {
    A p;
    A::B *d;
  };
  T & operator[](int i)
  {
    if (d->a != 1)
      f2 ();
    return reinterpret_cast <D *> (p.f1 (i))->f3 ();
  }
  void f2 ();
  void f3 (int i, const T & t);
};

class E
{
  int e, f;
};

C <E> c;

void
foo (int x)
{
  E e = c[x];
  c.f3 (x, e);
}