1 // PR tree-optimization/40813
2 // { dg-do compile }
3 // { dg-options "-O -fcheck-new" }
4 
5 typedef __SIZE_TYPE__ size_t;
6 typedef void *P;
7 struct A;
8 struct B
9 {
10   void *b[5];
fooB11   A *foo () { return (A *) & b[0]; }
12 };
13 struct A
14 {
newA15   void *operator new (size_t x, B &y) { return y.foo (); }
16 };
17 struct C : public A
18 {
barC19   virtual int bar () { }
20 };
21 struct D : public C
22 {
bazD23   static B baz (unsigned *x) { B b; new (b) D (x); return b; }
DD24   D (unsigned *x) { }
25 };
26 struct E
27 {
28   B e;
fnE29   B fn (unsigned *a) { return D::baz (a); }
EE30   E (P b, unsigned *a) : e (fn (a)) { }
31 };
32 
33 static unsigned *
fn2()34 fn2 ()
35 {
36 }
37 
38 void
test(P x)39 test (P x)
40 {
41   E (x, fn2 ());
42 }
43