| 1 |
// { dg-do compile } |
| 2 |
// { dg-options "-O2 -fstrict-aliasing -fno-store-merging -fdump-tree-optimized" } |
| 3 |
|
| 4 |
// Test that placement new does not introduce an unnecessary memory |
| 5 |
// barrier. |
| 6 |
// See PR 29286. |
| 7 |
|
| 8 |
typedef __SIZE_TYPE__ size_t; |
| 9 |
|
| 10 |
inline void* operator new(size_t, void* __p) throw() { return __p; } |
| 11 |
|
| 12 |
template <class T, int D> |
| 13 |
class Vector |
| 14 |
{ |
| 15 |
public: |
| 16 |
Vector() |
| 17 |
{ |
| 18 |
for (int i = 0; i < D; ++i) |
| 19 |
new (&x_m[i]) T(); |
| 20 |
} |
| 21 |
T& operator[](int i) { return x_m[i]; } |
| 22 |
|
| 23 |
private: |
| 24 |
T x_m[D]; |
| 25 |
}; |
| 26 |
|
| 27 |
void foo(Vector<float, 3> *m) |
| 28 |
{ |
| 29 |
Vector<float, 3> v; |
| 30 |
v[0] = 1.0; |
| 31 |
v[1] = 2.0; |
| 32 |
v[3] = 3.0; |
| 33 |
*m = v; |
| 34 |
} |
| 35 |
|
| 36 |
// { dg-final { scan-tree-dump-times "= 0\.0" 1 "optimized" } } |