1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // implicitly generated array constructors / assignment operators
14 #include <type_traits>
16 #include "test_macros.h"
18 // In C++03 the copy assignment operator is not deleted when the implicitly
19 // generated operator would be ill-formed; like in the case of a struct with a
22 # define TEST_NOT_COPY_ASSIGNABLE(T) ((void)0)
24 # define TEST_NOT_COPY_ASSIGNABLE(T) static_assert(!std::is_copy_assignable<T>::value, "")
28 TEST_CONSTEXPR
NoDefault(int) { }
31 struct NonTrivialCopy
{
32 TEST_CONSTEXPR
NonTrivialCopy() { }
33 TEST_CONSTEXPR
NonTrivialCopy(NonTrivialCopy
const&) { }
34 TEST_CONSTEXPR_CXX14 NonTrivialCopy
& operator=(NonTrivialCopy
const&) { return *this; }
37 TEST_CONSTEXPR_CXX14
bool tests()
40 typedef std::array
<double, 3> Array
;
41 Array array
= {1.1, 2.2, 3.3};
44 static_assert(std::is_copy_constructible
<Array
>::value
, "");
45 static_assert(std::is_copy_assignable
<Array
>::value
, "");
48 typedef std::array
<double const, 3> Array
;
49 Array array
= {1.1, 2.2, 3.3};
50 Array copy
= array
; (void)copy
;
51 static_assert(std::is_copy_constructible
<Array
>::value
, "");
52 TEST_NOT_COPY_ASSIGNABLE(Array
);
55 typedef std::array
<double, 0> Array
;
59 static_assert(std::is_copy_constructible
<Array
>::value
, "");
60 static_assert(std::is_copy_assignable
<Array
>::value
, "");
63 // const arrays of size 0 should disable the implicit copy assignment operator.
64 typedef std::array
<double const, 0> Array
;
66 Array copy
= array
; (void)copy
;
67 static_assert(std::is_copy_constructible
<Array
>::value
, "");
68 TEST_NOT_COPY_ASSIGNABLE(Array
);
71 typedef std::array
<NoDefault
, 0> Array
;
75 static_assert(std::is_copy_constructible
<Array
>::value
, "");
76 static_assert(std::is_copy_assignable
<Array
>::value
, "");
79 typedef std::array
<NoDefault
const, 0> Array
;
81 Array copy
= array
; (void)copy
;
82 static_assert(std::is_copy_constructible
<Array
>::value
, "");
83 TEST_NOT_COPY_ASSIGNABLE(Array
);
86 // Make sure we can implicitly copy a std::array of a non-trivially copyable type
88 typedef std::array
<NonTrivialCopy
, 0> Array
;
92 static_assert(std::is_copy_constructible
<Array
>::value
, "");
95 typedef std::array
<NonTrivialCopy
, 1> Array
;
99 static_assert(std::is_copy_constructible
<Array
>::value
, "");
102 typedef std::array
<NonTrivialCopy
, 2> Array
;
106 static_assert(std::is_copy_constructible
<Array
>::value
, "");
112 int main(int, char**)
115 #if TEST_STD_VER >= 14
116 static_assert(tests(), "");