1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
11 // UNSUPPORTED: libcpp-no-exceptions, libcpp-no-if-constexpr
12 // MODULES_DEFINES: _LIBCPP_DEBUG=1
13 // MODULES_DEFINES: _LIBCPP_DEBUG_USE_EXCEPTIONS
15 // Can't test the system lib because this test enables debug mode
16 // UNSUPPORTED: with_system_cxx_lib
18 // test container debugging
20 #define _LIBCPP_DEBUG 1
21 #define _LIBCPP_DEBUG_USE_EXCEPTIONS
25 #include "test_macros.h"
26 #include "debug_mode_helper.h"
28 using namespace IteratorDebugChecks;
30 typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> StringType;
32 template <class Container = StringType, ContainerType CT = CT_String>
33 struct StringContainerChecks : BasicContainerChecks<Container, CT> {
34 using Base = BasicContainerChecks<Container, CT_String>;
35 using value_type = typename Container::value_type;
36 using allocator_type = typename Container::allocator_type;
37 using iterator = typename Container::iterator;
38 using const_iterator = typename Container::const_iterator;
40 using Base::makeContainer;
41 using Base::makeValueType;
45 Base::run_iterator_tests();
46 Base::run_allocator_aware_tests();
48 for (int N : {3, 128}) {
49 FrontOnEmptyContainer(N);
50 BackOnEmptyContainer(N);
54 assert(false && "uncaught debug exception");
59 static void BackOnEmptyContainer(int N) {
60 CHECKPOINT("testing back on empty");
61 Container C = makeContainer(N);
62 Container const& CC = C;
63 iterator it = --C.end();
67 CHECK_DEBUG_THROWS( C.erase(it) );
69 CHECK_DEBUG_THROWS( C.back() );
70 CHECK_DEBUG_THROWS( CC.back() );
73 static void FrontOnEmptyContainer(int N) {
74 CHECKPOINT("testing front on empty");
75 Container C = makeContainer(N);
76 Container const& CC = C;
80 CHECK_DEBUG_THROWS( C.front() );
81 CHECK_DEBUG_THROWS( CC.front() );
84 static void PopBack(int N) {
85 CHECKPOINT("testing pop_back() invalidation");
86 Container C1 = makeContainer(N);
87 iterator it1 = C1.end();
90 CHECK_DEBUG_THROWS( C1.erase(it1) );
91 C1.erase(C1.begin(), C1.end());
92 assert(C1.size() == 0);
93 CHECK_DEBUG_THROWS( C1.pop_back() );
99 StringContainerChecks<>::run();