Commit 07758d90 by Jonathan Wakely Committed by Jonathan Wakely

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
parent 2bf2dacb
2019-10-11 Jonathan Wakely <jwakely@redhat.com> 2019-10-11 Jonathan Wakely <jwakely@redhat.com>
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.
* include/bits/charconv.h (__to_chars_len): Avoid -Wsign-compare * include/bits/charconv.h (__to_chars_len): Avoid -Wsign-compare
warnings. warnings.
......
...@@ -174,7 +174,7 @@ namespace tr2 ...@@ -174,7 +174,7 @@ namespace tr2
// Definitions of non-inline member functions. // Definitions of non-inline member functions.
template<typename _WordT, typename _Alloc> template<typename _WordT, typename _Alloc>
template<typename _CharT, typename _Traits> template<typename _Traits, typename _CharT>
void void
dynamic_bitset<_WordT, _Alloc>:: dynamic_bitset<_WordT, _Alloc>::
_M_copy_from_ptr(const _CharT* __str, size_t __len, _M_copy_from_ptr(const _CharT* __str, size_t __len,
......
// 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();
}
// 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();
}
// 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();
}
// 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();
}
// 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();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment