Add an UNSPEC_PROLOGUE_USE to prevent the link register from being considered dead.
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / bitset_ctor.cc
blob8dae3add5ea4d17888a343f1afe3e974beb5ff0e
1 // 1999-06-08 bkoz
3 // Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // 23.3.5.1 bitset constructors
23 #include <string>
24 #include <bitset>
25 #include <stdexcept>
26 #include <testsuite_hooks.h>
28 bool test01(void)
30 bool test = true;
32 // bitset()
33 const size_t n1 = 5;
34 std::bitset<n1> bit01;
35 for (int i = 0; i < n1; ++i)
36 VERIFY( !bit01.test(i) );
38 // bitset(unsigned long)
39 const size_t n2 = 32;
40 unsigned long ul1 = 2;
41 std::bitset<n2> bit02(ul1);
42 VERIFY( !bit02.test(0) );
43 VERIFY( bit02.test(1) );
44 VERIFY( !bit02.test(2) );
46 // template<_CharT, _Traits, _Alloc>
47 // explicit bitset(const basic_string<_C,_T,_A>&, size_type pos, size_type n)
48 std::string str01("stuff smith sessions");
49 const size_t n3 = 128;
50 try {
51 std::bitset<n3> bit03(str01, 5);
53 catch(std::invalid_argument& fail) {
54 VERIFY( true );
56 catch(...) {
57 VERIFY( false );
60 std::string str02("010101000011");
61 int sz = str02.size();
62 try {
63 std::bitset<n3> bit03(str02, 0);
64 std::string str03;
65 for (int i = 0; i < sz; ++i)
66 str03 += (bit03.test(i) ? '1' : '0');
67 std::reverse(str03.begin(), str03.end());
68 VERIFY( str03 == str02 );
70 catch(std::invalid_argument& fail) {
71 VERIFY( false );
73 catch(...) {
74 VERIFY( false );
78 #ifdef DEBUG_ASSERT
79 assert(test);
80 #endif
81 return test;
84 // boundary condition: a zero-sized set
85 // libstdc++/6282
86 bool test02(void)
88 using std::char_traits; using std::allocator;
89 bool test = true;
91 std::bitset<0> z1;
92 VERIFY( z1.any() == false );
94 std::bitset<0> z2(12345);
95 VERIFY( z2.any() == false );
97 std::bitset<0> z3(std::string("10101010101"));
98 VERIFY( z3.any() == false );
100 try {
101 z1.set(0);
102 VERIFY( false );
104 catch(std::out_of_range& fail) {
105 VERIFY( true );
107 catch(...) {
108 VERIFY( false );
111 VERIFY( z1.to_ulong() == 0 );
112 VERIFY( ( z1.to_string<char,char_traits<char>,allocator<char> >().empty() ) );
114 #ifdef DEBUG_ASSERT
115 assert(test);
116 #endif
117 return test;
120 int main()
122 test01();
123 test02();
125 return 0;