gdb/testsuite: fix gdb.trace/signal.exp on x86
[binutils-gdb/blckswan.git] / gdb / unittests / vec-utils-selftests.c
blob7e5c068c8a3f82926ae13cde3f34f33c9db3fcd2
1 /* Self tests for vector utility routines for GDB, the GNU debugger.
3 Copyright (C) 2019-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "gdbsupport/common-defs.h"
21 #include "gdbsupport/selftest.h"
23 #include "gdbsupport/gdb_vecs.h"
25 namespace selftests {
26 namespace vector_utils_tests {
28 static void
29 unordered_remove_tests ()
31 /* Create vector with a single object in, and then remove that object.
32 This test was added after a bug was discovered where unordered_remove
33 would cause a self move assign. If the C++ standard library is
34 compiled in debug mode (by passing -D_GLIBCXX_DEBUG=1) and the
35 operator= is removed from struct obj this test used to fail with an
36 error from the C++ standard library. */
37 struct obj
39 std::vector<void *> var;
41 obj() = default;
43 /* gcc complains if we provide an assignment operator but no copy
44 constructor, so provide one even if don't really care for this test. */
45 obj(const obj &other)
47 this->var = other.var;
50 obj &operator= (const obj &other)
52 if (this == &other)
53 error (_("detected self move assign"));
54 this->var = other.var;
55 return *this;
59 std::vector<obj> v;
60 v.emplace_back ();
61 auto it = v.end () - 1;
62 unordered_remove (v, it);
63 SELF_CHECK (v.empty ());
66 } /* namespace vector_utils_tests */
67 } /* amespace selftests */
69 void _initialize_vec_utils_selftests ();
70 void
71 _initialize_vec_utils_selftests ()
73 selftests::register_test
74 ("unordered_remove",
75 selftests::vector_utils_tests::unordered_remove_tests);