From 4b4b51445f7f3d11420439a92faaf5553f3128e3 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 22 Sep 2022 14:37:58 +0100 Subject: libstdc++: Rearrange tests for In C++03 std::bitset was in the Container clause, but since C++11 it has been in the Utilties clause. This moves the tests to the 20_util directory, where most people probably expect to find them. Also create 'access', 'observers', and 'io' subdirectories and group some tests under there, rather than having one directory per function name, and only a single test in that directory. libstdc++-v3/ChangeLog: * testsuite/23_containers/bitset/18604.cc: Moved to... * testsuite/20_util/bitset/18604.cc: ...here. * testsuite/23_containers/bitset/45713.cc: Moved to... * testsuite/20_util/bitset/45713.cc: ...here. * testsuite/23_containers/bitset/to_string/dr396.cc: Moved to... * testsuite/20_util/bitset/access/dr396.cc: ...here. * testsuite/23_containers/bitset/to_string/1.cc: Moved to... * testsuite/20_util/bitset/access/to_string.cc: ...here. * testsuite/23_containers/bitset/to_ullong/1.cc: Moved to... * testsuite/20_util/bitset/access/to_ullong.cc: ...here. * testsuite/23_containers/bitset/to_ulong/1.cc: Moved to... * testsuite/20_util/bitset/access/to_ulong.cc: ...here. * testsuite/23_containers/bitset/cons/1.cc: Moved to... * testsuite/20_util/bitset/cons/1.cc: ...here. * testsuite/23_containers/bitset/cons/16020.cc: Moved to... * testsuite/20_util/bitset/cons/16020.cc: ...here. * testsuite/23_containers/bitset/cons/2.cc: Moved to... * testsuite/20_util/bitset/cons/2.cc: ...here. * testsuite/23_containers/bitset/cons/3.cc: Moved to... * testsuite/20_util/bitset/cons/3.cc: ...here. * testsuite/23_containers/bitset/cons/38244.cc: Moved to... * testsuite/20_util/bitset/cons/38244.cc: ...here. * testsuite/23_containers/bitset/cons/50268.cc: Moved to... * testsuite/20_util/bitset/cons/50268.cc: ...here. * testsuite/23_containers/bitset/cons/6282.cc: Moved to... * testsuite/20_util/bitset/cons/6282.cc: ...here. * testsuite/23_containers/bitset/cons/constexpr.cc: Moved to... * testsuite/20_util/bitset/cons/constexpr.cc: ...here. * testsuite/23_containers/bitset/cons/dr1325-1.cc: Moved to... * testsuite/20_util/bitset/cons/dr1325-1.cc: ...here. * testsuite/23_containers/bitset/cons/dr1325-2.cc: Moved to... * testsuite/20_util/bitset/cons/dr1325-2.cc: ...here. * testsuite/23_containers/bitset/cons/dr396.cc: Moved to... * testsuite/20_util/bitset/cons/dr396.cc: ...here. * testsuite/23_containers/bitset/debug/invalidation/1.cc: Moved to... * testsuite/20_util/bitset/debug/invalidation/1.cc: ...here. * testsuite/23_containers/bitset/ext/15361.cc: Moved to... * testsuite/20_util/bitset/ext/15361.cc: ...here. * testsuite/23_containers/bitset/hash/1.cc: Moved to... * testsuite/20_util/bitset/hash/1.cc: ...here. * testsuite/23_containers/bitset/input/1.cc: Moved to... * testsuite/20_util/bitset/io/input.cc: ...here. * testsuite/23_containers/bitset/count/6124.cc: Moved to... * testsuite/20_util/bitset/observers/6124.cc: ...here. * testsuite/23_containers/bitset/all/1.cc: Moved to... * testsuite/20_util/bitset/observers/all.cc: ...here. * testsuite/23_containers/bitset/test/1.cc: Moved to... * testsuite/20_util/bitset/observers/test.cc: ...here. * testsuite/23_containers/bitset/operations/1.cc: Moved to... * testsuite/20_util/bitset/operations/1.cc: ...here. * testsuite/23_containers/bitset/operations/13838.cc: Moved to... * testsuite/20_util/bitset/operations/13838.cc: ...here. * testsuite/23_containers/bitset/operations/2.cc: Moved to... * testsuite/20_util/bitset/operations/2.cc: ...here. * testsuite/23_containers/bitset/operations/96303.cc: Moved to... * testsuite/20_util/bitset/operations/96303.cc: ...here. * testsuite/23_containers/bitset/operations/constexpr-2.cc: Moved to... * testsuite/20_util/bitset/operations/constexpr-2.cc: ...here. * testsuite/23_containers/bitset/operations/constexpr.cc: Moved to... * testsuite/20_util/bitset/operations/constexpr.cc: ...here. * testsuite/23_containers/bitset/requirements/constexpr_functions.cc: Moved to... * testsuite/20_util/bitset/requirements/constexpr_functions.cc: ...here. * testsuite/23_containers/bitset/requirements/explicit_instantiation/1.cc: Moved to... * testsuite/20_util/bitset/requirements/explicit_instantiation/1.cc: ...here. * testsuite/23_containers/bitset/requirements/explicit_instantiation/1_c++0x.cc: Moved to... * testsuite/20_util/bitset/requirements/explicit_instantiation/1_c++0x.cc: ...here. * testsuite/23_containers/headers/bitset/synopsis.cc: Moved to... * testsuite/20_util/headers/bitset/synopsis.cc: ...here. --- libstdc++-v3/testsuite/20_util/bitset/18604.cc | 41 ++++++++ libstdc++-v3/testsuite/20_util/bitset/45713.cc | 26 +++++ .../testsuite/20_util/bitset/access/dr396.cc | 64 +++++++++++++ .../testsuite/20_util/bitset/access/to_string.cc | 52 ++++++++++ .../testsuite/20_util/bitset/access/to_ullong.cc | 42 ++++++++ .../testsuite/20_util/bitset/access/to_ulong.cc | 46 +++++++++ libstdc++-v3/testsuite/20_util/bitset/cons/1.cc | 80 ++++++++++++++++ .../testsuite/20_util/bitset/cons/16020.cc | 40 ++++++++ libstdc++-v3/testsuite/20_util/bitset/cons/2.cc | 44 +++++++++ libstdc++-v3/testsuite/20_util/bitset/cons/3.cc | 60 ++++++++++++ .../testsuite/20_util/bitset/cons/38244.cc | 43 +++++++++ .../testsuite/20_util/bitset/cons/50268.cc | 82 ++++++++++++++++ libstdc++-v3/testsuite/20_util/bitset/cons/6282.cc | 61 ++++++++++++ .../testsuite/20_util/bitset/cons/constexpr.cc | 36 +++++++ .../testsuite/20_util/bitset/cons/dr1325-1.cc | 25 +++++ .../testsuite/20_util/bitset/cons/dr1325-2.cc | 80 ++++++++++++++++ .../testsuite/20_util/bitset/cons/dr396.cc | 49 ++++++++++ .../20_util/bitset/debug/invalidation/1.cc | 47 +++++++++ libstdc++-v3/testsuite/20_util/bitset/ext/15361.cc | 39 ++++++++ libstdc++-v3/testsuite/20_util/bitset/hash/1.cc | 45 +++++++++ libstdc++-v3/testsuite/20_util/bitset/io/input.cc | 49 ++++++++++ .../testsuite/20_util/bitset/observers/6124.cc | 38 ++++++++ .../testsuite/20_util/bitset/observers/all.cc | 78 +++++++++++++++ .../testsuite/20_util/bitset/observers/test.cc | 50 ++++++++++ .../testsuite/20_util/bitset/operations/1.cc | 106 +++++++++++++++++++++ .../testsuite/20_util/bitset/operations/13838.cc | 45 +++++++++ .../testsuite/20_util/bitset/operations/2.cc | 38 ++++++++ .../testsuite/20_util/bitset/operations/96303.cc | 31 ++++++ .../20_util/bitset/operations/constexpr-2.cc | 35 +++++++ .../20_util/bitset/operations/constexpr.cc | 30 ++++++ .../bitset/requirements/constexpr_functions.cc | 54 +++++++++++ .../requirements/explicit_instantiation/1.cc | 25 +++++ .../requirements/explicit_instantiation/1_c++0x.cc | 24 +++++ .../testsuite/20_util/headers/bitset/synopsis.cc | 50 ++++++++++ 34 files changed, 1655 insertions(+) create mode 100644 libstdc++-v3/testsuite/20_util/bitset/18604.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/45713.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/access/dr396.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/access/to_string.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/access/to_ullong.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/access/to_ulong.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/cons/1.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/cons/16020.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/cons/2.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/cons/3.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/cons/38244.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/cons/50268.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/cons/6282.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/cons/constexpr.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/cons/dr1325-1.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/cons/dr1325-2.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/cons/dr396.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/debug/invalidation/1.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/ext/15361.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/hash/1.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/io/input.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/observers/6124.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/observers/all.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/observers/test.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/operations/1.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/operations/13838.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/operations/2.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/operations/96303.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/operations/constexpr-2.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/operations/constexpr.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/requirements/constexpr_functions.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/requirements/explicit_instantiation/1.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/requirements/explicit_instantiation/1_c++0x.cc create mode 100644 libstdc++-v3/testsuite/20_util/headers/bitset/synopsis.cc (limited to 'libstdc++-v3/testsuite/20_util') diff --git a/libstdc++-v3/testsuite/20_util/bitset/18604.cc b/libstdc++-v3/testsuite/20_util/bitset/18604.cc new file mode 100644 index 00000000000..f91cdfa6bb7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/18604.cc @@ -0,0 +1,41 @@ +// 2005-05-09 Paolo Carlini + +// Copyright (C) 2005-2022 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 +// . + +// NB: This issue affected only debug-mode. + +// { dg-do compile } + +// libstdc++/18604 +struct less; +struct allocator; +struct pair; +struct binary_function; +struct iterator; +struct iterator_traits; +struct bidirectional_iterator_tag; +struct forward_iterator_tag; +struct input_iterator_tag; +struct random_access_iterator_tag; +struct ios_base; +struct basic_string; +struct basic_istream; +struct basic_ostream; +struct char_traits; + +#include diff --git a/libstdc++-v3/testsuite/20_util/bitset/45713.cc b/libstdc++-v3/testsuite/20_util/bitset/45713.cc new file mode 100644 index 00000000000..5cec1b5240e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/45713.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2010-2022 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 +// . + +// The testcase requires bitsizetype to be wider than sizetype, +// otherwise types/vars with (e.g. for 32-bit sizetype) 0x20000000 +// bytes or larger can't be used. See http://gcc.gnu.org/PR54897 +// { dg-do compile { target { ! { avr*-*-* cris*-*-* h8300*-*-* hppa*64*-*-* mcore*-*-* moxie*-*-* mmix-*-* } } } } + +#include + +// libstdc++/45713 +int test[sizeof(std::bitset<__SIZE_MAX__>) != 1 ? 1 : -1]; diff --git a/libstdc++-v3/testsuite/20_util/bitset/access/dr396.cc b/libstdc++-v3/testsuite/20_util/bitset/access/dr396.cc new file mode 100644 index 00000000000..dfba27ed3af --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/access/dr396.cc @@ -0,0 +1,64 @@ +// 2008-09-23 Paolo Carlini + +// Copyright (C) 2008-2022 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 +// . + +// 23.3.5.2 bitset members + +#include +#include + +// DR 396. what are characters zero and one. +void test01() +{ + using namespace std; + using std::bitset; // Work around struct ::bitset on rtems. + + bitset<5> b5; + string s0 = b5.to_string, allocator >('a', 'b'); + VERIFY( s0 == "aaaaa" ); + + string s1 = b5.to_string, allocator >('b'); + VERIFY( s1 == "bbbbb" ); + + b5.set(0); + string s2 = b5.to_string >('c', 'd'); + VERIFY( s2 == "ccccd" ); + + string s3 = b5.to_string >('d'); + VERIFY( s3 == "dddd1" ); + + b5.set(2); + string s4 = b5.to_string('e', 'f'); + VERIFY( s4 == "eefef" ); + + string s5 = b5.to_string('f'); + VERIFY( s5 == "ff1f1" ); + + b5.set(4); + string s6 = b5.to_string('g', 'h'); + VERIFY( s6 == "hghgh" ); + + string s7 = b5.to_string('h'); + VERIFY( s7 == "1h1h1" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/access/to_string.cc b/libstdc++-v3/testsuite/20_util/bitset/access/to_string.cc new file mode 100644 index 00000000000..8384eb96d25 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/access/to_string.cc @@ -0,0 +1,52 @@ +// 2004-11-17 Paolo Carlini + +// Copyright (C) 2004-2022 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 +// . + +// 23.3.5.2 bitset members + +#include +#include + +void test01() +{ + using namespace std; + using std::bitset; // Work around struct ::bitset on rtems. + + bitset<5> b5; + string s0 = b5.to_string, allocator >(); + VERIFY( s0 == "00000" ); + + // DR 434. bitset::to_string() hard to use. + b5.set(0); + string s1 = b5.to_string >(); + VERIFY( s1 == "00001" ); + + b5.set(2); + string s2 = b5.to_string(); + VERIFY( s2 == "00101" ); + + b5.set(4); + string s3 = b5.to_string(); + VERIFY( s3 == "10101" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/access/to_ullong.cc b/libstdc++-v3/testsuite/20_util/bitset/access/to_ullong.cc new file mode 100644 index 00000000000..18fc0772d1c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/access/to_ullong.cc @@ -0,0 +1,42 @@ +// { dg-do run { target c++11 } } + +// 2009-12-29 Paolo Carlini + +// Copyright (C) 2009-2022 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 +// . + +#include +#include + +void test01() +{ + std::bitset<0> bs0; + VERIFY( bs0.to_ullong() == 0 ); + + std::bitset<64> bs1("11010111"); + VERIFY( bs1.to_ullong() == 215 ); + + std::bitset<64> bs2("10110100100010000100000101111111" + "01111110011111110001110001100011"); + VERIFY( bs2.to_ullong() == 13008719539498589283ULL ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/access/to_ulong.cc b/libstdc++-v3/testsuite/20_util/bitset/access/to_ulong.cc new file mode 100644 index 00000000000..8163701e342 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/access/to_ulong.cc @@ -0,0 +1,46 @@ +// 2001-06-03 pme + +// Copyright (C) 2001-2022 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 +// . + +// 23.3.5.2 bitset members + +#include +#include +#include +#include + +void test03() +{ + std::bitset<5> b; + std::stringstream ss("101"); + ss.exceptions(std::ios_base::eofbit); + + try + { + ss >> b; + } + catch (std::exception&) { } + + VERIFY( b.to_ulong() == 5 ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/cons/1.cc b/libstdc++-v3/testsuite/20_util/bitset/cons/1.cc new file mode 100644 index 00000000000..c2a54c37cc5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/cons/1.cc @@ -0,0 +1,80 @@ +// 1999-06-08 bkoz + +// Copyright (C) 1999-2022 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 +// . + +// 23.3.5.1 bitset constructors + +#include +#include +#include // std::reverse +#include +#include + +void test01(void) +{ + // bitset() + const size_t n1 = 5; + std::bitset bit01; + for (size_t i = 0; i < n1; ++i) + VERIFY( !bit01.test(i) ); + + // bitset(unsigned long) + const size_t n2 = 32; + unsigned long ul1 = 2; + std::bitset bit02(ul1); + VERIFY( !bit02.test(0) ); + VERIFY( bit02.test(1) ); + VERIFY( !bit02.test(2) ); + + // template<_CharT, _Traits, _Alloc> + // explicit bitset(const basic_string<_C,_T,_A>&, size_type pos, size_type n) + std::string str01("stuff smith sessions"); + const size_t n3 = 128; + try { + std::bitset bit03(str01, 5); + } + catch(std::invalid_argument& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + std::string str02("010101000011"); + int sz = str02.size(); + try { + std::bitset bit03(str02, 0); + std::string str03; + for (int i = 0; i < sz; ++i) + str03 += (bit03.test(i) ? '1' : '0'); + std::reverse(str03.begin(), str03.end()); + VERIFY( str03 == str02 ); + } + catch(std::invalid_argument& fail) { + VERIFY( false ); + } + catch(...) { + VERIFY( false ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/cons/16020.cc b/libstdc++-v3/testsuite/20_util/bitset/cons/16020.cc new file mode 100644 index 00000000000..ffccdd2df8a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/cons/16020.cc @@ -0,0 +1,40 @@ +// Copyright (C) 2004-2022 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 +// . + +#include +#include + +// libstdc++/16020 +void test01() +{ + using __gnu_debug::bitset; + + bitset<5> b(7); + bitset<5> c; + + bitset<5> bb(b); + c = bb; + + VERIFY( bb == b ); + VERIFY( c == bb ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/cons/2.cc b/libstdc++-v3/testsuite/20_util/bitset/cons/2.cc new file mode 100644 index 00000000000..947124ebcc8 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/cons/2.cc @@ -0,0 +1,44 @@ +// { dg-do run { target c++11 } } + +// Copyright (C) 2009-2022 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 +// . + +#include +#include +#include + +struct X +{ + operator const char*() { return "10101010"; } +}; + +void +test01() +{ + X x; + std::string s(x); + std::bitset<32> b1(static_cast(x)); + std::bitset<32> b2(s); + VERIFY( b1 == b2 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/cons/3.cc b/libstdc++-v3/testsuite/20_util/bitset/cons/3.cc new file mode 100644 index 00000000000..6308e4ec899 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/cons/3.cc @@ -0,0 +1,60 @@ +// { dg-do run { target c++11 } } + +// 2009-12-31 Paolo Carlini + +// Copyright (C) 2009-2022 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 +// . + +#include +#include + +void test01() +{ + const unsigned long long num0 = 0ULL; + std::bitset<0> bs0(num0); + VERIFY( bs0.to_ullong() == num0 ); + + const unsigned long long num1 = 215ULL; + std::bitset<32> bs1(num1); + VERIFY( bs1.to_ullong() == num1 ); + + const unsigned long long num2 = 215ULL; + std::bitset<64> bs2(num2); + VERIFY( bs2.to_ullong() == num2 ); + + const unsigned long long num3 = 343353215ULL; + std::bitset<32> bs3(num3); + VERIFY( bs3.to_ullong() == num3 ); + + const unsigned long long num4 = 343353215ULL; + std::bitset<64> bs4(num4); + VERIFY( bs4.to_ullong() == num4 ); + + const unsigned long long num5 = 13008719539498589283ULL; + std::bitset<64> bs5(num5); + VERIFY( bs5.to_ullong() == num5 ); + + const unsigned long long num6 = 13008719539498589283ULL; + std::bitset<128> bs6(num6); + VERIFY( bs6.to_ullong() == num6 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/cons/38244.cc b/libstdc++-v3/testsuite/20_util/bitset/cons/38244.cc new file mode 100644 index 00000000000..610197c4965 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/cons/38244.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2008-2022 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 +// . + +// { dg-do compile } + +#include + +class C0 +{ + public: + C0() : b(0) { } + private: + std::bitset<1> b; +}; + +class C1 +{ + public: + C1() : b(1) { } + private: + std::bitset<1> b; +}; + +// libstdc++/38244 +void func() +{ + C0 val0; + C1 val1; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/cons/50268.cc b/libstdc++-v3/testsuite/20_util/bitset/cons/50268.cc new file mode 100644 index 00000000000..6d4b946c35f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/cons/50268.cc @@ -0,0 +1,82 @@ +// { dg-do run { target c++11 } } + +// Copyright (C) 2011-2022 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 +// . + +#include +#include + +// libstdc++/50268 +void test01() +{ + std::bitset<1> b1(3ULL); + VERIFY( b1.count() == 1ULL ); + + std::bitset<3> b2(30ULL); + VERIFY( b2.count() == 2ULL ); + + std::bitset<6> b3(300ULL); + VERIFY( b3.count() == 3ULL ); + + std::bitset<9> b4(3000ULL); + VERIFY( b4.count() == 5ULL ); + + std::bitset<16> b5(300000ULL); + VERIFY( b5.count() == 7ULL ); + + std::bitset<24> b6(30000000ULL); + VERIFY( b6.count() == 9ULL ); + + std::bitset<32> b7(30000000000ULL); + VERIFY( b7.count() == 13ULL ); + + std::bitset<37> b8(3000000000000ULL); + VERIFY( b8.count() == 18ULL ); + + std::bitset<40> b9(30000000000000ULL); + VERIFY( b9.count() == 16ULL ); + + std::bitset<45> b10(30000000000000ULL); + VERIFY( b10.count() == 20ULL ); + + std::bitset<64> b11(30000000000000ULL); + VERIFY( b11.count() == 20ULL ); + + std::bitset<100> b12(30000000000000ULL); + VERIFY( b12.count() == 20ULL ); + + std::bitset<200> b13(30000000000000ULL); + VERIFY( b13.count() == 20ULL ); + + std::bitset<45> b14(18446744073709551615ULL); + VERIFY( b14.count() == 45ULL ); + + std::bitset<64> b15(18446744073709551615ULL); + VERIFY( b15.count() == 64ULL ); + + std::bitset<100> b16(18446744073709551615ULL); + VERIFY( b16.count() == 64ULL ); + + std::bitset<200> b17(18446744073709551615ULL); + VERIFY( b17.count() == 64ULL ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/cons/6282.cc b/libstdc++-v3/testsuite/20_util/bitset/cons/6282.cc new file mode 100644 index 00000000000..5409336bf2e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/cons/6282.cc @@ -0,0 +1,61 @@ +// 1999-06-08 bkoz + +// Copyright (C) 1999-2022 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 +// . + +// 23.3.5.1 bitset constructors + +#include +#include +#include +#include + +// boundary condition: a zero-sized set +// libstdc++/6282 +void test02(void) +{ + using std::char_traits; using std::allocator; + + std::bitset<0> z1; + VERIFY( z1.any() == false ); + + std::bitset<0> z2(12345); + VERIFY( z2.any() == false ); + + std::bitset<0> z3(std::string("10101010101")); + VERIFY( z3.any() == false ); + + try { + z1.set(0); + VERIFY( false ); + } + catch(std::out_of_range& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + VERIFY( z1.to_ulong() == 0 ); + VERIFY( (z1.to_string,allocator >().empty() )); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/bitset/cons/constexpr.cc new file mode 100644 index 00000000000..bf16b19dc63 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/cons/constexpr.cc @@ -0,0 +1,36 @@ +// { dg-do compile { target c++11 } } + +// Copyright (C) 2010-2022 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 +// . + +#include +#include + +int main() +{ + __gnu_test::constexpr_default_constructible test1; + test1.operator()>(); + test1.operator()>(); + test1.operator()>(); + + __gnu_test::constexpr_single_value_constructible test2; + test2.operator(), unsigned long long>(); + test2.operator(), unsigned long long>(); + test2.operator(), unsigned long long>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/cons/dr1325-1.cc b/libstdc++-v3/testsuite/20_util/bitset/cons/dr1325-1.cc new file mode 100644 index 00000000000..aa50804d288 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/cons/dr1325-1.cc @@ -0,0 +1,25 @@ +// { dg-do compile { target c++11 } } + +// 2010-10-11 Paolo Carlini + +// Copyright (C) 2010-2022 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 +// . + +#include + +// DR 1325. +std::bitset<10> b(0); diff --git a/libstdc++-v3/testsuite/20_util/bitset/cons/dr1325-2.cc b/libstdc++-v3/testsuite/20_util/bitset/cons/dr1325-2.cc new file mode 100644 index 00000000000..2371bef09cc --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/cons/dr1325-2.cc @@ -0,0 +1,80 @@ +// { dg-do run { target c++11 } } + +// 2010-10-11 Paolo Carlini + +// Copyright (C) 2010-2022 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 +// . + +#include +#include + +template + std::bitset + test01_ref(const CharT* str, + typename std::basic_string::size_type n + = std::basic_string::npos, + CharT zero = CharT('0'), CharT one = CharT('1')) + { + return std::bitset(n == std::basic_string::npos + ? std::basic_string(str) + : std::basic_string(str, n), + 0, n, zero, one); + } + +// DR 1325. +void test01() +{ + using namespace std; + using std::bitset; // Work around struct ::bitset on rtems. + + const char s1[4] = { '0', '1', '0', '1' }; + VERIFY( bitset<4>(s1, 4) == test01_ref<4>(s1, 4) ); + + const char s2[3] = { '1', '1', '0' }; + VERIFY( bitset<6>(s2, 3) == test01_ref<6>(s2, 3) ); + + const char* s3 = "1110110"; + VERIFY( bitset<7>(s3) == test01_ref<7>(s3) ); + + const char* s4 = "0011"; + VERIFY( bitset<10>(s4) == test01_ref<10>(s4) ); + + const char* s5 = "011110000111001"; + VERIFY( bitset<5>(s5) == test01_ref<5>(s5) ); + + const char* s6 = "1cc1c1"; + VERIFY( bitset<6>(s6, basic_string::npos, 'c') + == test01_ref<6>(s6, basic_string::npos, 'c') ); + + const char* s7 = "001011101"; + VERIFY( bitset<9>(s7, basic_string::npos, '0', '1') + == test01_ref<9>(s7, basic_string::npos, '0', '1') ); + + const char* s8 = "babb"; + VERIFY( bitset<4>(s8, basic_string::npos, 'a', 'b') + == test01_ref<4>(s8, basic_string::npos, 'a', 'b') ); + + const char* s9 = "bbabbbaaa"; + VERIFY( bitset<100>(s9, basic_string::npos, 'a', 'b') + == test01_ref<100>(s9, basic_string::npos, 'a', 'b') ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/cons/dr396.cc b/libstdc++-v3/testsuite/20_util/bitset/cons/dr396.cc new file mode 100644 index 00000000000..f1f9d876c2e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/cons/dr396.cc @@ -0,0 +1,49 @@ +// 2009-09-23 Paolo Carlini + +// Copyright (C) 2008-2022 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 +// . + +#include +#include + +// DR 396. what are characters zero and one. +void test01() +{ + std::bitset<4> z1(std::string("bbab"), 0, std::string::npos, 'a', 'b'); + VERIFY( z1.to_string('a', 'b') == "bbab" ); + + std::bitset<4> z2(std::string("11a1"), 0, std::string::npos, 'a'); + VERIFY( z2.to_string('a') == "11a1" ); + + std::bitset<8> z3(std::string("babb"), 0, std::string::npos, 'a', 'b'); + VERIFY( z3.to_string('a', 'b') == "aaaababb" ); + + std::bitset<8> z4(std::string("1a11"), 0, std::string::npos, 'a'); + VERIFY( z4.to_string('a') == "aaaa1a11" ); + + std::bitset<2> z5(std::string("bbab"), 0, std::string::npos, 'a', 'b'); + VERIFY( z5.to_string('a', 'b') == "bb" ); + + std::bitset<2> z6(std::string("11a1"), 0, std::string::npos, 'a'); + VERIFY( z6.to_string('a') == "11" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/debug/invalidation/1.cc b/libstdc++-v3/testsuite/20_util/bitset/debug/invalidation/1.cc new file mode 100644 index 00000000000..5d0e3c15171 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/debug/invalidation/1.cc @@ -0,0 +1,47 @@ +// Bitset reference invalidation tests + +// Copyright (C) 2003-2022 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 +// . + +#include +#include + +using __gnu_debug::bitset; + +bool test = true; + +// Disappear +void test01() +{ + bitset<32>::reference* i; + { + bitset<32> bs; + bs.flip(7); + i = new bitset<32>::reference(bs[7]); + VERIFY(*i); + } +#if __cplusplus < 201103L + VERIFY(i->_M_singular()); +#endif + delete i; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/ext/15361.cc b/libstdc++-v3/testsuite/20_util/bitset/ext/15361.cc new file mode 100644 index 00000000000..392470084ae --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/ext/15361.cc @@ -0,0 +1,39 @@ +// Copyright (C) 2004-2022 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 +// . + +#include +#include + +// libstdc++/15361 +void test01() +{ + using namespace std; + using std::bitset; // Work around struct ::bitset on rtems. + + bitset<256> b; + b.set(225); + b.set(226); + + VERIFY( b._Find_first() == 225 ); + VERIFY( b._Find_next(225) == 226 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/hash/1.cc b/libstdc++-v3/testsuite/20_util/bitset/hash/1.cc new file mode 100644 index 00000000000..aba6b726cfe --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/hash/1.cc @@ -0,0 +1,45 @@ +// { dg-do run { target c++11 } } + +// Copyright (C) 2010-2022 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 +// . + +#include + +void test01() +{ + std::bitset<0> b0; + std::hash> h0; + h0(b0); + + std::bitset<10> b1; + std::hash> h1; + h1(b1); + + std::bitset<100> b2; + std::hash> h2; + h2(b2); + + std::bitset<1000> b3; + std::hash> h3; + h3(b3); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/io/input.cc b/libstdc++-v3/testsuite/20_util/bitset/io/input.cc new file mode 100644 index 00000000000..939861b171e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/io/input.cc @@ -0,0 +1,49 @@ +// 2003-12-03 Paolo Carlini + +// Copyright (C) 2003-2022 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 +// . + +// 23.3.5.3 bitset operators + +#include +#include +#include + +void test01() +{ + using namespace std; + using std::bitset; // Work around struct ::bitset on rtems. + + bitset<5> b5; + bitset<0> b0; + stringstream ss; + + ss.str("*"); + ss >> b5; + VERIFY( ss.rdstate() == ios_base::failbit ); + + ss.clear(); + ss.str("*"); + ss >> b0; + VERIFY( ss.rdstate() == ios_base::goodbit ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/observers/6124.cc b/libstdc++-v3/testsuite/20_util/bitset/observers/6124.cc new file mode 100644 index 00000000000..d08211cec8a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/observers/6124.cc @@ -0,0 +1,38 @@ +// 2001-06-03 pme + +// Copyright (C) 2001-2022 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 +// . + +// 23.3.5.2 bitset members + +#include +#include +#include +#include + +// libstdc++/6124 +void test02() +{ + std::bitset<1> bs; + bs.count(); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/observers/all.cc b/libstdc++-v3/testsuite/20_util/bitset/observers/all.cc new file mode 100644 index 00000000000..9840f25058c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/observers/all.cc @@ -0,0 +1,78 @@ +// 2007-11-23 Paolo Carlini + +// Copyright (C) 2007-2022 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 +// . + +// 23.3.5.2 bitset members + +#include +#include + +// DR 693. std::bitset::all() missing. +void test01() +{ + std::bitset<0> z1; + VERIFY( z1.all() ); + z1.set(); + VERIFY( z1.all() ); + + std::bitset<8> z2; + VERIFY( !z2.all() ); + z2.set(); + VERIFY( z2.all() ); + + std::bitset<16> z3; + VERIFY( !z3.all() ); + z3.set(); + VERIFY( z3.all() ); + + std::bitset<32> z4; + VERIFY( !z4.all() ); + z4.set(); + VERIFY( z4.all() ); + + std::bitset<64> z5; + VERIFY( !z5.all() ); + z5.set(); + VERIFY( z5.all() ); + + std::bitset<96> z6; + VERIFY( !z6.all() ); + z6.set(); + VERIFY( z6.all() ); + + std::bitset<128> z7; + VERIFY( !z7.all() ); + z7.set(); + VERIFY( z7.all() ); + + std::bitset<192> z8; + VERIFY( !z8.all() ); + z8.set(); + VERIFY( z8.all() ); + + std::bitset<1024> z9; + VERIFY( !z9.all() ); + z9.set(); + VERIFY( z9.all() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/observers/test.cc b/libstdc++-v3/testsuite/20_util/bitset/observers/test.cc new file mode 100644 index 00000000000..2444499e621 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/observers/test.cc @@ -0,0 +1,50 @@ +// 2001-06-03 pme + +// Copyright (C) 2001-2022 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 +// . + +// 23.3.5.2 bitset members + +#include +#include +#include +#include + +void +test01(void) +{ + const size_t n1 = 5; + + // the other 22 member functions should be in here too... + try { + std::bitset five_bits; + bool unused __attribute__((unused)) = five_bits.test(n1); // should throw + VERIFY( false ); + } + catch(std::out_of_range& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/operations/1.cc b/libstdc++-v3/testsuite/20_util/bitset/operations/1.cc new file mode 100644 index 00000000000..58942107790 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/operations/1.cc @@ -0,0 +1,106 @@ +// 2000-01-15 Anders Widell + +// Copyright (C) 2000-2022 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 +// . + +#include +#include +#include +#include + +static char original_bits[1024]; +static char left_shifted[1024]; +static char right_shifted[1024]; + +char +random_bit() { + static long x = 1; + return ((x = (3432L*x + 6789L) % 9973L) & 1) + '0'; +} + +void +initialise(size_t size) { + for (size_t i=0; i + bool + do_test() + { + bool test = true; + + std::bitset shifted; + std::bitset correct; + + initialise(size); + + //std::bitset original = std::string(original_bits); + std::bitset original = std::bitset (std::string(original_bits)); + + for (size_t shift_step=0; shift_step==0 || shift_step (std::string(left_shifted)); + VERIFY( shifted == correct ); + + shifted = original; + shifted >>= shift_step; + //correct = std::string(right_shifted); + correct = std::bitset (std::string(right_shifted)); + VERIFY( shifted == correct ); + } + + return test; + } + +void +test01() { + VERIFY( do_test<32>() ); + VERIFY( do_test<48>() ); + VERIFY( do_test<64>() ); + + VERIFY( do_test<511>() ); + VERIFY( do_test<513>() ); + VERIFY( do_test<997>() ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/operations/13838.cc b/libstdc++-v3/testsuite/20_util/bitset/operations/13838.cc new file mode 100644 index 00000000000..c38ccc3911d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/operations/13838.cc @@ -0,0 +1,45 @@ +// Copyright (C) 2004-2022 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 +// . + +#include +#include + +// libstdc++/13838 +void test01() +{ + using __gnu_debug::bitset; + + bitset<4> b0, b1; + b0.set(1); + b0.set(3); + b1.set(2); + b1.set(3); + + b0 |= b1; + + bitset<4> br; + br.set(1); + br.set(2); + br.set(3); + + VERIFY( b0 == br ); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/operations/2.cc b/libstdc++-v3/testsuite/20_util/bitset/operations/2.cc new file mode 100644 index 00000000000..a909e387189 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/operations/2.cc @@ -0,0 +1,38 @@ +// 2000-01-15 Anders Widell + +// Copyright (C) 2000-2022 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 +// . + +#include +#include +#include +#include + +void +test02() +{ + std::bitset<66> b; + b <<= 400; + VERIFY( b.count() == 0 ); +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/operations/96303.cc b/libstdc++-v3/testsuite/20_util/bitset/operations/96303.cc new file mode 100644 index 00000000000..b1f729d70f3 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/operations/96303.cc @@ -0,0 +1,31 @@ +// Copyright (C) 2020-2022 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 +// . + +// { dg-options "-std=gnu++2a -pedantic" } +// { dg-do compile { target c++2a } } + +#include + +bool +test01() +{ + __gnu_debug::bitset<1> b; + // PR libstdc++/96303 + bool eq = b == b; + bool ne = b != b; + return eq && !ne; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/operations/constexpr-2.cc b/libstdc++-v3/testsuite/20_util/bitset/operations/constexpr-2.cc new file mode 100644 index 00000000000..91098d92ef9 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/operations/constexpr-2.cc @@ -0,0 +1,35 @@ +// { dg-do compile { target c++11 } } +// { dg-require-normal-mode "" } + +// Copyright (C) 2011-2022 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 +// . + +#include + +int main() +{ + // bitset base type + typedef std::_Base_bitset<6> bitset_base; + constexpr bitset_base base = bitset_base(); + + constexpr auto r1 __attribute__((unused)) = base._M_getword(2); + // constexpr auto r2 = base._M_getdata(); // error, pointer to this + auto r2 __attribute__((unused)) = base._M_getdata(); + constexpr auto r3 __attribute__((unused)) = base._M_hiword(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/operations/constexpr.cc b/libstdc++-v3/testsuite/20_util/bitset/operations/constexpr.cc new file mode 100644 index 00000000000..3f77003d564 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/operations/constexpr.cc @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +// Copyright (C) 2011-2022 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 +// . + +#include + +int main() +{ + // bitset operators + typedef std::bitset<6> bitset_type; + constexpr bitset_type a = bitset_type(); + constexpr auto v __attribute__((unused)) = a[0]; + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/requirements/constexpr_functions.cc b/libstdc++-v3/testsuite/20_util/bitset/requirements/constexpr_functions.cc new file mode 100644 index 00000000000..a3c90472685 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/requirements/constexpr_functions.cc @@ -0,0 +1,54 @@ +// { dg-do compile { target c++11 } } + +// Copyright (C) 2010-2022 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 +// . + +#include +#include + +namespace __gnu_test +{ + struct constexpr_member_functions + { + template + void + operator()() + { + struct _Concept + { + void __constraint() + { + constexpr _Ttesttype obj; + constexpr auto v1 __attribute__((unused)) = obj.size(); + // constexpr auto v2 = obj[4]; + } + }; + + _Concept c; + c.__constraint(); + } + }; +} + +int main() +{ + __gnu_test::constexpr_member_functions test; + test.operator()>(); + test.operator()>(); + test.operator()>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bitset/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/20_util/bitset/requirements/explicit_instantiation/1.cc new file mode 100644 index 00000000000..d1d8f57b569 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/requirements/explicit_instantiation/1.cc @@ -0,0 +1,25 @@ +// { dg-do compile } + +// Copyright (C) 2007-2022 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 +// . + + +// This file tests explicit instantiation of library containers. + +#include + +template class std::bitset<10>; diff --git a/libstdc++-v3/testsuite/20_util/bitset/requirements/explicit_instantiation/1_c++0x.cc b/libstdc++-v3/testsuite/20_util/bitset/requirements/explicit_instantiation/1_c++0x.cc new file mode 100644 index 00000000000..9a1c1477c1c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bitset/requirements/explicit_instantiation/1_c++0x.cc @@ -0,0 +1,24 @@ +// { dg-do compile { target c++11 } } + +// Copyright (C) 2009-2022 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 +// . + +// This file tests explicit instantiation of library containers. + +#include + +template class std::bitset<10>; diff --git a/libstdc++-v3/testsuite/20_util/headers/bitset/synopsis.cc b/libstdc++-v3/testsuite/20_util/headers/bitset/synopsis.cc new file mode 100644 index 00000000000..e7ea4f89a4a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/bitset/synopsis.cc @@ -0,0 +1,50 @@ +// { dg-do compile } +// { dg-require-normal-mode "" } +// { dg-require-normal-namespace "" } + +// Copyright (C) 2007-2022 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 +// . + +#include + +#if __cplusplus >= 201103L +# define NOTHROW noexcept +#else +# define NOTHROW +#endif + +namespace std { + template class bitset; + + // 23.3.5.3 bitset operations: + template + bitset operator&(const bitset&, const bitset&) NOTHROW; + + template + bitset operator|(const bitset&, const bitset&) NOTHROW; + + template + bitset operator^(const bitset&, const bitset&) NOTHROW; + + template + basic_istream& + operator>>(basic_istream& is, bitset& x); + + template + basic_ostream& + operator<<(basic_ostream& os, const bitset& x); +} -- cgit v1.2.1