Debian Codegraph @

libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy_n/102064.cc

raw
1 // { dg-do compile { target c++11 } }
2
3 #include <memory>
4 #include <algorithm>
5
6 struct X;
7
8 struct Y
9 {
10 operator X() const;
11 };
12
13 struct X
14 {
15 private:
16 void operator=(const Y&);
17 };
18
19 Y::operator X() const { return X(); }
20
21 static_assert( std::is_trivially_default_constructible<X>::value, "" );
22 static_assert( std::is_trivially_copyable<X>::value, "" );
23
24 void test01_pr102064()
25 {
26 unsigned char buf[sizeof(X)];
27 X* addr = reinterpret_cast<X*>(buf);
28 const Y y[1] = { };
29 std::uninitialized_copy_n(y, 1, addr);
30 }
31
32 struct Z
33 {
34 Z() = default;
35 Z(int) { }
36 Z(const Z&) = default;
37 Z& operator=(const Z&) = default;
38 Z& operator=(int) = delete;
39 };
40
41 static_assert( std::is_trivially_default_constructible<Z>::value, "" );
42 static_assert( std::is_trivially_copyable<Z>::value, "" );
43
44 void test02_pr102064()
45 {
46 unsigned char buf[sizeof(Z)];
47 Z* addr = reinterpret_cast<Z*>(buf);
48 const int i[1] = { 99 };
49 std::uninitialized_copy_n(i, 1, addr);
50 }