summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/init/new17.C
blob: 42b9f077a1f5add675e55a79f152a92c3dde946b (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
// { dg-do compile }
// { dg-options "-O2 -fstrict-aliasing -fdump-tree-optimized" }

// Test that placement new does not introduce an unnecessary memory
// barrier.
// See PR 29286.

typedef __SIZE_TYPE__ size_t;

inline void* operator new(size_t, void* __p) throw() { return __p; }

template <class T, int D>
class Vector
{
public:
   Vector()
   {
     for (int i = 0; i < D; ++i)
        new (&x_m[i]) T();
   }
   T& operator[](int i) { return x_m[i]; }

private:
   T x_m[D];
};

void foo(Vector<float, 3> *m)
{
  Vector<float, 3> v;
  v[0] = 1.0;
  v[1] = 2.0;
  v[3] = 3.0;
  *m = v;
}

// { dg-final { scan-tree-dump-times "= 0\.0" 1 "optimized" } }
// { dg-final { cleanup-tree-dump "optimized" } }