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// UNSUPPORTED: c++03
10// ADDITIONAL_COMPILE_FLAGS: -Wno-unused-function
11
12#include <cassert>
13#include <utility>
14
15#include "../src/demangle/ItaniumDemangle.h"
16
17void testPODSmallVector() {
18 { // {push/pop}_back
19 itanium_demangle::PODSmallVector<int, 1> PSV;
20 PSV.push_back(Elem: 0);
21 PSV.push_back(Elem: 1);
22 PSV.push_back(Elem: 2);
23 PSV.push_back(Elem: 3);
24 for (int i = 0; i < 4; ++i)
25 assert(PSV[i] == i);
26 PSV.pop_back();
27 for (int i = 0; i < 3; ++i)
28 assert(PSV[i] == i);
29 PSV.pop_back();
30 PSV.pop_back();
31 assert(!PSV.empty() && PSV.size() == 1);
32 PSV.pop_back();
33 assert(PSV.empty() && PSV.size() == 0);
34 }
35
36 {
37 itanium_demangle::PODSmallVector<int, 1> PSV1;
38 PSV1.push_back(Elem: 1);
39 PSV1.push_back(Elem: 2);
40 PSV1.push_back(Elem: 3);
41
42 itanium_demangle::PODSmallVector<int, 1> PSV2;
43 std::swap(a&: PSV1, b&: PSV2);
44 assert(PSV1.size() == 0);
45 assert(PSV2.size() == 3);
46 int i = 1;
47 for (int x : PSV2) {
48 assert(x == i);
49 ++i;
50 }
51 assert(i == 4);
52 std::swap(a&: PSV1, b&: PSV2);
53 assert(PSV1.size() == 3);
54 assert(PSV2.size() == 0);
55 i = 1;
56 for (int x : PSV1) {
57 assert(x == i);
58 ++i;
59 }
60 assert(i == 4);
61 }
62
63 {
64 itanium_demangle::PODSmallVector<int, 10> PSV1;
65 itanium_demangle::PODSmallVector<int, 10> PSV2;
66 PSV1.push_back(Elem: 0);
67 PSV1.push_back(Elem: 1);
68 PSV1.push_back(Elem: 2);
69 assert(PSV1.size() == 3);
70 assert(PSV2.size() == 0);
71 std::swap(a&: PSV1, b&: PSV2);
72 assert(PSV1.size() == 0);
73 assert(PSV2.size() == 3);
74 int i = 0;
75 for (int x : PSV2) {
76 assert(x == i);
77 ++i;
78 }
79 for (int x : PSV1) {
80 assert(false);
81 (void)x;
82 }
83 }
84}
85
86int main(int, char**) {
87 testPODSmallVector();
88 return 0;
89}
90

source code of libcxxabi/test/unittest_demangle.pass.cpp