1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <array>
11 
12 // implicitly generated array constructors / assignment operators
13 
14 #include <array>
15 #include <type_traits>
16 #include <cassert>
17 #include "test_macros.h"
18 
19 // std::array is explicitly allowed to be initialized with A a = { init-list };.
20 // Disable the missing braces warning for this reason.
21 #include "disable_missing_braces_warning.h"
22 
23 // In C++03 the copy assignment operator is not deleted when the implicitly
24 // generated operator would be ill-formed; like in the case of a struct with a
25 // const member.
26 #if TEST_STD_VER < 11
27 #define TEST_NOT_COPY_ASSIGNABLE(T) ((void)0)
28 #else
29 #define TEST_NOT_COPY_ASSIGNABLE(T) static_assert(!std::is_copy_assignable<T>::value, "")
30 #endif
31 
32 struct NoDefault {
NoDefaultNoDefault33   NoDefault(int) {}
34 };
35 
main()36 int main() {
37   {
38     typedef double T;
39     typedef std::array<T, 3> C;
40     C c = {1.1, 2.2, 3.3};
41     C c2 = c;
42     c2 = c;
43     static_assert(std::is_copy_constructible<C>::value, "");
44     static_assert(std::is_copy_assignable<C>::value, "");
45   }
46   {
47     typedef double T;
48     typedef std::array<const T, 3> C;
49     C c = {1.1, 2.2, 3.3};
50     C c2 = c;
51     ((void)c2);
52     static_assert(std::is_copy_constructible<C>::value, "");
53     TEST_NOT_COPY_ASSIGNABLE(C);
54   }
55   {
56     typedef double T;
57     typedef std::array<T, 0> C;
58     C c = {};
59     C c2 = c;
60     c2 = c;
61     static_assert(std::is_copy_constructible<C>::value, "");
62     static_assert(std::is_copy_assignable<C>::value, "");
63   }
64   {
65     // const arrays of size 0 should disable the implicit copy assignment operator.
66     typedef double T;
67     typedef std::array<const T, 0> C;
68     C c = {{}};
69     C c2 = c;
70     ((void)c2);
71     static_assert(std::is_copy_constructible<C>::value, "");
72     TEST_NOT_COPY_ASSIGNABLE(C);
73   }
74   {
75     typedef NoDefault T;
76     typedef std::array<T, 0> C;
77     C c = {};
78     C c2 = c;
79     c2 = c;
80     static_assert(std::is_copy_constructible<C>::value, "");
81     static_assert(std::is_copy_assignable<C>::value, "");
82   }
83   {
84     typedef NoDefault T;
85     typedef std::array<const T, 0> C;
86     C c = {{}};
87     C c2 = c;
88     ((void)c2);
89     static_assert(std::is_copy_constructible<C>::value, "");
90     TEST_NOT_COPY_ASSIGNABLE(C);
91   }
92 
93 }
94