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 // <string>
10 
11 // Call __clear_and_shrink() and ensure string invariants hold
12 
13 #include <string>
14 #include <cassert>
15 
16 #include "test_macros.h"
17 
18 int main(int, char**)
19 {
20     std::string l = "Long string so that allocation definitely, for sure, absolutely happens. Probably.";
21     std::string s = "short";
22 
23     assert(l.__invariants());
24     assert(s.__invariants());
25 
26     s.__clear_and_shrink();
27     assert(s.__invariants());
28     assert(s.size() == 0);
29 
30     {
31     std::string::size_type cap = l.capacity();
32     l.__clear_and_shrink();
33     assert(l.__invariants());
34     assert(l.size() == 0);
35     assert(l.capacity() < cap);
36     }
37 
38     return 0;
39 }
40