OpenMP: Fix typo in atomic directive error message
[gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / fill / 109150.cc
blob9491a998ff0258e80aaa4c8c975d26223cc87806
1 // { dg-do run }
3 // Test the problematic cases identified in PR libstdc++/109150
4 // where the previous std::fill was non-conforming.
6 #include <algorithm>
7 #include <testsuite_hooks.h>
9 const int global = 0;
11 struct X {
12 void operator=(const int& i) { VERIFY(&i == &global); }
15 void
16 test_identity_matters()
18 X x;
19 // Assigning int to X has non-trivial side effects, so we cannot
20 // hoist the load outside the loop, we have to do exactly what the
21 // standard says to do.
22 std::fill(&x, &x+1, global);
25 struct Y {
26 int i;
27 void operator=(int ii) { i = ii + 1; }
30 void
31 test_self_aliasing()
33 Y y[2] = { };
34 // Assigning int to X has non-trivial side effects, altering the value
35 // used to fill the later elements. Must not load it outside the loop.
36 std::fill(y, y+2, y[0].i);
37 VERIFY(y[1].i == 2);
40 struct Z
42 Z() { }
43 #if __cplusplus >= 201103L
44 explicit Z(const Z&) = default;
45 #endif
48 void
49 test_explicit_copy_ctor()
51 Z z;
52 // The optimization that copies the fill value must use direct-initialization
53 // otherwise this case would be ill-formed due to the explicit constructor.
54 std::fill(&z, &z, z);
57 int main()
59 test_identity_matters();
60 test_self_aliasing();
61 test_explicit_copy_ctor();