mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-21 04:42:53 +08:00
4b09bb2eff
When building with gcc 9.2.0, I get the following build error: In file included from /home/simark/src/binutils-gdb/gdb/unittests/vec-utils-selftests.c:23: /home/simark/src/binutils-gdb/gdb/gdbsupport/gdb_vecs.h: In instantiation of ‘T unordered_remove(std::__debug::vector<T>&, typename std::__debug::vector<T>::iterator) [with T = selftests::vector_utils_tests::unordered_remove_tests()::obj; typename std::__debug::vector<T>::iterator = __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<selftests::vector_utils_tests::unordered_remove_tests()::obj*, std::__cxx1998::vector<selftests::vector_utils_tests::unordered_remove_tests()::obj, std::allocator<selftests::vector_utils_tests::unordered_remove_tests()::obj> > >, std::__debug::vector<selftests::vector_utils_tests::unordered_remove_tests()::obj>, std::random_access_iterator_tag>]’: /home/simark/src/binutils-gdb/gdb/unittests/vec-utils-selftests.c:53:26: required from here /home/simark/src/binutils-gdb/gdb/gdbsupport/gdb_vecs.h:53:5: error: implicitly-declared ‘selftests::vector_utils_tests::unordered_remove_tests()::obj::obj(const selftests::vector_utils_tests::unordered_remove_tests()::obj&)’ is deprecated [-Werror=deprecated-copy] 53 | T removed = std::move (*it); | ^~~~~~~ /home/simark/src/binutils-gdb/gdb/unittests/vec-utils-selftests.c:41:10: note: because ‘selftests::vector_utils_tests::unordered_remove_tests()::obj’ has user-provided ‘selftests::vector_utils_tests::unordered_remove_tests()::obj& selftests::vector_utils_tests::unordered_remove_tests()::obj::operator=(const selftests::vector_utils_tests::unordered_remove_tests()::obj&)’ 41 | obj &operator= (const obj &other) | ^~~~~~~~ In file included from /home/simark/src/binutils-gdb/gdb/unittests/vec-utils-selftests.c:23: /home/simark/src/binutils-gdb/gdb/gdbsupport/gdb_vecs.h:58:10: error: implicitly-declared ‘selftests::vector_utils_tests::unordered_remove_tests()::obj::obj(const selftests::vector_utils_tests::unordered_remove_tests()::obj&)’ is deprecated [-Werror=deprecated-copy] 58 | return removed; | ^~~~~~~ /home/simark/src/binutils-gdb/gdb/unittests/vec-utils-selftests.c:41:10: note: because ‘selftests::vector_utils_tests::unordered_remove_tests()::obj’ has user-provided ‘selftests::vector_utils_tests::unordered_remove_tests()::obj& selftests::vector_utils_tests::unordered_remove_tests()::obj::operator=(const selftests::vector_utils_tests::unordered_remove_tests()::obj&)’ 41 | obj &operator= (const obj &other) | ^~~~~~~~ I think gcc is just trying to be nice and recommends the good practice of providing a copy constructor if an assignment operator is provided. Silence the warning by providing that copy constructor. gdb/ChangeLog: * unittests/vec-utils-selftests.c (unordered_remove_tests::obj): Provide explicit default and copy constructor. Change-Id: I323361b1c120bf8525613b74e7e5983910e002df
76 lines
2.2 KiB
C
76 lines
2.2 KiB
C
/* Self tests for vector utility routines for GDB, the GNU debugger.
|
|
|
|
Copyright (C) 2019 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#include "gdbsupport/common-defs.h"
|
|
#include "gdbsupport/selftest.h"
|
|
|
|
#include "gdbsupport/gdb_vecs.h"
|
|
|
|
namespace selftests {
|
|
namespace vector_utils_tests {
|
|
|
|
static void
|
|
unordered_remove_tests ()
|
|
{
|
|
/* Create vector with a single object in, and then remove that object.
|
|
This test was added after a bug was discovered where unordered_remove
|
|
would cause a self move assign. If the C++ standard library is
|
|
compiled in debug mode (by passing -D_GLIBCXX_DEBUG=1) and the
|
|
operator= is removed from struct obj this test used to fail with an
|
|
error from the C++ standard library. */
|
|
struct obj
|
|
{
|
|
std::vector<void *> var;
|
|
|
|
obj() = default;
|
|
|
|
/* gcc complains if we provide an assignment operator but no copy
|
|
constructor, so provide one even if don't really care for this test. */
|
|
obj(const obj &other)
|
|
{
|
|
this->var = other.var;
|
|
}
|
|
|
|
obj &operator= (const obj &other)
|
|
{
|
|
if (this == &other)
|
|
error (_("detected self move assign"));
|
|
this->var = other.var;
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
std::vector<obj> v;
|
|
v.emplace_back ();
|
|
auto it = v.end () - 1;
|
|
unordered_remove (v, it);
|
|
SELF_CHECK (v.empty ());
|
|
}
|
|
|
|
} /* namespace vector_utils_tests */
|
|
} /* amespace selftests */
|
|
|
|
void
|
|
_initialize_vec_utils_selftests ()
|
|
{
|
|
selftests::register_test
|
|
("unordered_remove",
|
|
selftests::vector_utils_tests::unordered_remove_tests);
|
|
}
|