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
21int main(int, char**) {
22 {
23 typedef NotConstructible T;
24 typedef std::deque<T> C;
25 C c;
26 ASSERT_NOEXCEPT(c.clear());
27 c.clear();
28 assert(std::distance(c.begin(), c.end()) == 0);
29 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
30 }
31 {
32 typedef int T;
33 typedef std::deque<T> C;
34 const T t[] = {0, 1, 2, 3, 4};
35 C c(std::begin(t), std::end(t));
36
37 ASSERT_NOEXCEPT(c.clear());
38 c.clear();
39 assert(std::distance(c.begin(), c.end()) == 0);
40 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
41
42 c.clear();
43 assert(std::distance(c.begin(), c.end()) == 0);
44 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
45 }
46#if TEST_STD_VER >= 11
47 {
48 typedef NotConstructible T;
49 typedef std::deque<T, min_allocator<T>> C;
50 C c;
51 ASSERT_NOEXCEPT(c.clear());
52 c.clear();
53 assert(std::distance(c.begin(), c.end()) == 0);
54 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
55 }
56 {
57 typedef int T;
58 typedef std::deque<T, min_allocator<T>> C;
59 const T t[] = {0, 1, 2, 3, 4};
60 C c(std::begin(t), std::end(t));
61
62 ASSERT_NOEXCEPT(c.clear());
63 c.clear();
64 assert(std::distance(c.begin(), c.end()) == 0);
65 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
66
67 c.clear();
68 assert(std::distance(c.begin(), c.end()) == 0);
69 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
70 }
71#endif
72
73 return 0;
74}
75

source code of libcxx/test/std/containers/sequences/deque/deque.modifiers/clear.pass.cpp