summaryrefslogtreecommitdiff
path: root/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp
blob: 920c0d185261287bb8ef17ea0122b9cbbd944c3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// <string>

// Call __clear_and_shrink() and ensure string invariants hold

#if _LIBCPP_DEBUG >= 1

#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))

#include <string>
#include <cassert>

int main()
{
    std::string l = "Long string so that allocation definitely, for sure, absolutely happens. Probably.";
    std::string s = "short";

    assert(l.__invariants());
    assert(s.__invariants());

    s.__clear_and_shrink();
    assert(s.__invariants());
    assert(s.size() == 0);

    {
    std::string::size_type cap = l.capacity();
    l.__clear_and_shrink();
    assert(l.__invariants());
    assert(l.size() == 0);
    assert(l.capacity() < cap);
    }
}

#else

int main()
{
}

#endif