Debian Codegraph @

gcc/testsuite/g++.dg/opt/pr113705.C

raw
1 // PR middle-end/113705
2 // { dg-do compile { target c++17 } }
3 // { dg-options "-O2 -w" }
4
5 void foo ();
6 template <typename T> struct A : T { long bar () const; };
7 int a;
8
9 template <typename T>
10 long
11 A<T>::bar () const
12 {
13 return this->baz ()[a];
14 }
15
16 struct B {
17 struct { long b[1]; long c; } u;
18 unsigned d;
19 int e;
20 B (const B &);
21 ~B ();
22 const long *baz () const;
23 unsigned qux () const;
24 };
25
26 B::B (const B &)
27 {
28 if (__builtin_expect (e, 0))
29 u.c = 0;
30 }
31
32 B::~B ()
33 {
34 if (__builtin_expect (e, 0))
35 foo ();
36 }
37
38 const long *
39 B::baz () const
40 {
41 return u.b;
42 }
43
44 unsigned
45 B::qux () const
46 {
47 return d;
48 }
49
50 struct C { A<B> corge () const; A<B> *f; };
51
52 A<B>
53 C::corge () const
54 {
55 return f[1];
56 }
57
58 void
59 test (C r, long *h, unsigned short *d)
60 {
61 for (int j = 0; j < 8; ++j)
62 {
63 A g = r.corge ();
64 *d = g.qux ();
65 for (unsigned i = 0; i < *d; ++i)
66 *h++ = g.bar ();
67 }
68 }