xref: /llvm-project/libcxx/test/std/containers/sequences/deque/deque.modifiers/clear.pass.cpp (revision 10ec9276d40024c23a481e6671dad1521151dd85)
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 // <deque>
10 
11 // void clear() noexcept;
12 
13 #include "asan_testing.h"
14 #include <deque>
15 #include <cassert>
16 
17 #include "test_macros.h"
18 #include "../../../NotConstructible.h"
19 #include "min_allocator.h"
20 
main(int,char **)21 int main(int, char**)
22 {
23     {
24         typedef NotConstructible T;
25         typedef std::deque<T> C;
26         C c;
27         ASSERT_NOEXCEPT(c.clear());
28         c.clear();
29         assert(std::distance(c.begin(), c.end()) == 0);
30         LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
31     }
32     {
33         typedef int T;
34         typedef std::deque<T> C;
35         const T t[] = {0, 1, 2, 3, 4};
36         C c(std::begin(t), std::end(t));
37 
38         ASSERT_NOEXCEPT(c.clear());
39         c.clear();
40         assert(std::distance(c.begin(), c.end()) == 0);
41         LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
42 
43         c.clear();
44         assert(std::distance(c.begin(), c.end()) == 0);
45         LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
46     }
47 #if TEST_STD_VER >= 11
48     {
49         typedef NotConstructible T;
50         typedef std::deque<T, min_allocator<T>> C;
51         C c;
52         ASSERT_NOEXCEPT(c.clear());
53         c.clear();
54         assert(std::distance(c.begin(), c.end()) == 0);
55         LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
56     }
57     {
58         typedef int T;
59         typedef std::deque<T, min_allocator<T>> C;
60         const T t[] = {0, 1, 2, 3, 4};
61         C c(std::begin(t), std::end(t));
62 
63         ASSERT_NOEXCEPT(c.clear());
64         c.clear();
65         assert(std::distance(c.begin(), c.end()) == 0);
66         LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
67 
68         c.clear();
69         assert(std::distance(c.begin(), c.end()) == 0);
70         LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
71     }
72 #endif
73 
74   return 0;
75 }
76