1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <vector>
10 
11 // typedef ... iterator;
12 // typedef ... const_iterator;
13 
14 // The libc++ __bit_iterator type has weird ABI calling conventions as a quirk
15 // of the implementation. The const bit iterator is trivial, but the non-const
16 // bit iterator is not because it declares a user-defined copy constructor.
17 //
18 // Changing this now is an ABI break, so this test ensures that each type
19 // is trivial/non-trivial as expected.
20 
21 // The definition of 'non-trivial for the purposes of calls':
22 //   A type is considered non-trivial for the purposes of calls if:
23 //     * it has a non-trivial copy constructor, move constructor, or
24 //       destructor, or
25 //     * all of its copy and move constructors are deleted.
26 
27 // UNSUPPORTED: c++03
28 
29 #include <cassert>
30 #include <type_traits>
31 #include <vector>
32 
33 template <class T>
34 using IsTrivialForCall = std::integral_constant<bool,
35   std::is_trivially_copy_constructible<T>::value &&
36   std::is_trivially_move_constructible<T>::value &&
37   std::is_trivially_destructible<T>::value
38   // Ignore the all-deleted case, it shouldn't occur here.
39   >;
40 
test_const_iterator()41 void test_const_iterator() {
42   using It = std::vector<bool>::const_iterator;
43   static_assert(IsTrivialForCall<It>::value, "");
44 }
45 
test_non_const_iterator()46 void test_non_const_iterator() {
47   using It = std::vector<bool>::iterator;
48   static_assert(!IsTrivialForCall<It>::value, "");
49 }
50 
main(int,char **)51 int main(int, char**) {
52   test_const_iterator();
53   test_non_const_iterator();
54 
55   return 0;
56 }
57