diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2019-10-11 16:29:55 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2019-10-11 16:29:55 +0100 |
commit | 07758d90c7bc6b80b10a83bac52f9ab9e394131d (patch) | |
tree | 471b8a23cc4ad0e7c100d147ad0f5b63bc744864 /libstdc++-v3/testsuite/tr2 | |
parent | 2bf2dacb355af3632fd98b2f9e920f1e03722049 (diff) | |
download | gcc-07758d90c7bc6b80b10a83bac52f9ab9e394131d.zip gcc-07758d90c7bc6b80b10a83bac52f9ab9e394131d.tar.gz gcc-07758d90c7bc6b80b10a83bac52f9ab9e394131d.tar.bz2 |
PR libstdc++/92059 fix several bugs in tr2::dynamic_bitset
PR libstdc++/92059
* include/tr2/dynamic_bitset (__dynamic_bitset_base): Define all
special member functions as defaulted. Add noexcept to most members.
(__dynamic_bitset_base(size_t, unsigned long long, const _Alloc&)):
Mask off unwanted bits in the __val parameter. Avoid undefined left
shifts.
(__dynamic_bitset_base::_M_assign): Remove.
(__dynamic_bitset_base::_M_do_reset): Use std::fill.
(__dynamic_bitset_base::_M_are_all_aux): Avoid integer promotion when
block_type has lower rank than int.
(dynamic_bitset): Add noexcept to most members. Use injected-class-name
in return types and parameter types.
(dynamic_bitset::_M_Nb): Add default member initializer.
(dynamic_bitset(), dynamic_bitset(const dynamic_bitset&)): Define as
defaulted.
(dynamic_bitset(dynamic_bitset&&)): Clear source object after move.
(dynamic_bitset::operator=(const dynamic_bitset&)): Define as
defaulted.
(dynamic_bitset::operator=(dynamic_bitset&&)): Add noexcept-specifier.
Define without using swap, to propagate allocator correctly.
(dynamic_bitset(const char*, const _Alloc&)): Use strlen.
(dynamic_bitset::_M_do_sanitize, dynamic_bitset::_M_do_fill): Use
casts to avoid unwanted integer promotions.
(dynamic_bitset::_M_copy_from_ptr): Rearrange template parameters and
add default template arguments and default argument to simplify usage.
(dynamic_bitset::_M_copy_from_string): Adjust call to _M_copy_from_ptr.
(operator==(const dynamic_bitset&, const dynamic_bitset&))
(operator<(const dynamic_bitset&, const dynamic_bitset&)): Use _M_Nb.
* include/tr2/dynamic_bitset.tcc (dynamic_bitset::_M_copy_from_ptr):
Adjust template parameters to match declaration.
* testsuite/tr2/dynamic_bitset/cmp.cc: New test.
* testsuite/tr2/dynamic_bitset/cons.cc: New test.
* testsuite/tr2/dynamic_bitset/copy.cc: New test.
* testsuite/tr2/dynamic_bitset/move.cc: New test.
* testsuite/tr2/dynamic_bitset/pr92059.cc: New test.
From-SVN: r276890
Diffstat (limited to 'libstdc++-v3/testsuite/tr2')
-rw-r--r-- | libstdc++-v3/testsuite/tr2/dynamic_bitset/cmp.cc | 50 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/tr2/dynamic_bitset/cons.cc | 105 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/tr2/dynamic_bitset/copy.cc | 55 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/tr2/dynamic_bitset/move.cc | 53 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/tr2/dynamic_bitset/pr92059.cc | 36 |
5 files changed, 299 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/tr2/dynamic_bitset/cmp.cc b/libstdc++-v3/testsuite/tr2/dynamic_bitset/cmp.cc new file mode 100644 index 0000000..a811307 --- /dev/null +++ b/libstdc++-v3/testsuite/tr2/dynamic_bitset/cmp.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This library 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 library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-do run { target c++11 } } + +#include <tr2/dynamic_bitset> +#include <testsuite_hooks.h> + +void +test01() +{ + std::tr2::dynamic_bitset<> a(100); + std::tr2::dynamic_bitset<> b = a; + VERIFY( a == b ); + b.resize(99); + VERIFY( a != b ); +} + +void +test02() +{ + std::tr2::dynamic_bitset<> a(100); + std::tr2::dynamic_bitset<> b = a; + VERIFY( !(a < b) ); + VERIFY( !(b < a) ); + b.resize(99); + VERIFY( !(a < b) ); + VERIFY( b < a ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/tr2/dynamic_bitset/cons.cc b/libstdc++-v3/testsuite/tr2/dynamic_bitset/cons.cc new file mode 100644 index 0000000..9e21a91 --- /dev/null +++ b/libstdc++-v3/testsuite/tr2/dynamic_bitset/cons.cc @@ -0,0 +1,105 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This library 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 library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-do run { target c++11 } } + +#include <tr2/dynamic_bitset> +#include <testsuite_hooks.h> + +void +test01() +{ + std::tr2::dynamic_bitset<> a; + VERIFY( a.size() == 0 ); + VERIFY( a.empty() ); + std::tr2::dynamic_bitset<> b(1); + VERIFY( b.size() == 1 ); + VERIFY( !b.empty() ); + VERIFY( a != b ); +} + +void +test02() +{ + std::tr2::dynamic_bitset<> a(1, 0); // { 0 } + std::tr2::dynamic_bitset<> b(2, 2); // { 0, 1 } + VERIFY( a != b ); +} + +void +test03() +{ + std::tr2::dynamic_bitset<> a; + a.resize(1); // { 0 } + std::tr2::dynamic_bitset<> b(2, 2); // { 0, 1 } + VERIFY( a != b ); +} + +void +test04() +{ + std::tr2::dynamic_bitset<> a(3, 2); // { 0, 1, 0 } + std::tr2::dynamic_bitset<> b(2, 2); // { 0, 1 } + VERIFY( a != b ); +} + +void +test05() +{ + std::tr2::dynamic_bitset<unsigned short> a(1, 0); // { 0 } + std::tr2::dynamic_bitset<unsigned short> b(2, 2); // { 0, 1 } + VERIFY( a != b ); +} + +void +test06() +{ + std::tr2::dynamic_bitset<unsigned short> a; + a.resize(1); // { 0 } + std::tr2::dynamic_bitset<unsigned short> b(2, 2); // { 0, 1 } + VERIFY( a != b ); +} + +void +test07() +{ + std::tr2::dynamic_bitset<unsigned short> a(3, 2); // { 0, 1, 0 } + std::tr2::dynamic_bitset<unsigned short> b(2, 2); // { 0, 1 } + VERIFY( a != b ); +} + +void +test08() +{ + std::tr2::dynamic_bitset<> a(65, -1ULL); + std::tr2::dynamic_bitset<> b(64, -1ULL); + b.push_back(0); + VERIFY( a == b ); +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); + test05(); + test06(); + test07(); + test08(); +} diff --git a/libstdc++-v3/testsuite/tr2/dynamic_bitset/copy.cc b/libstdc++-v3/testsuite/tr2/dynamic_bitset/copy.cc new file mode 100644 index 0000000..06bc115 --- /dev/null +++ b/libstdc++-v3/testsuite/tr2/dynamic_bitset/copy.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This library 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 library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-do run { target c++11 } } + +#include <tr2/dynamic_bitset> +#include <testsuite_hooks.h> + +void +test01() +{ + std::tr2::dynamic_bitset<> a(100); + const auto n = a.num_blocks(); + std::tr2::dynamic_bitset<> b = a; + VERIFY(b.num_blocks() == n); + VERIFY(b.size() == 100); + VERIFY(a.num_blocks() == n); + VERIFY(a.size() == 100); + VERIFY(b == a); +} + +void +test02() +{ + std::tr2::dynamic_bitset<> a(100); + const auto n = a.num_blocks(); + std::tr2::dynamic_bitset<> b; + b = a; + VERIFY(b.num_blocks() == n); + VERIFY(b.size() == 100); + VERIFY(a.num_blocks() == n); + VERIFY(a.size() == 100); + VERIFY(b == a); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/tr2/dynamic_bitset/move.cc b/libstdc++-v3/testsuite/tr2/dynamic_bitset/move.cc new file mode 100644 index 0000000..ed320db --- /dev/null +++ b/libstdc++-v3/testsuite/tr2/dynamic_bitset/move.cc @@ -0,0 +1,53 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This library 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 library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-do run { target c++11 } } + +#include <tr2/dynamic_bitset> +#include <testsuite_hooks.h> + +void +test01() +{ + std::tr2::dynamic_bitset<> a(100); + const auto n = a.num_blocks(); + std::tr2::dynamic_bitset<> b = std::move(a); + VERIFY(b.num_blocks() == n); + VERIFY(b.size() == 100); + VERIFY(a.num_blocks() == 0); + VERIFY(a.size() == 0); +} + +void +test02() +{ + std::tr2::dynamic_bitset<> a(100); + const auto n = a.num_blocks(); + std::tr2::dynamic_bitset<> b; + b = std::move(a); + VERIFY(b.num_blocks() == n); + VERIFY(b.size() == 100); + VERIFY(a.num_blocks() == 0); + VERIFY(a.size() == 0); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/tr2/dynamic_bitset/pr92059.cc b/libstdc++-v3/testsuite/tr2/dynamic_bitset/pr92059.cc new file mode 100644 index 0000000..0aec1ad --- /dev/null +++ b/libstdc++-v3/testsuite/tr2/dynamic_bitset/pr92059.cc @@ -0,0 +1,36 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This library 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 library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-do run { target c++11 } } + +#include <tr2/dynamic_bitset> +#include <testsuite_hooks.h> + +void +test01() +{ + // PR libstdc++/92059 + std::tr2::dynamic_bitset<> b1(10000), b2(10000); + b2 = b1; // crashed on missing return + VERIFY( b2 == b1); +} + +int +main() +{ + test01(); +} |