1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // XFAIL: libcpp-no-exceptions
11 // test constexpr bool test(size_t pos) const;
12 
13 #include <bitset>
14 #include <cstdlib>
15 #include <cassert>
16 
17 #pragma clang diagnostic ignored "-Wtautological-compare"
18 
19 template <std::size_t N>
20 std::bitset<N>
21 make_bitset()
22 {
23     std::bitset<N> v;
24     for (std::size_t i = 0; i < N; ++i)
25         v[i] = static_cast<bool>(std::rand() & 1);
26     return v;
27 }
28 
29 template <std::size_t N>
30 void test_test()
31 {
32     const std::bitset<N> v1 = make_bitset<N>();
33     try
34     {
35         bool b = v1.test(50);
36         if (50 >= v1.size())
37             assert(false);
38         assert(b == v1[50]);
39     }
40     catch (std::out_of_range&)
41     {
42     }
43 }
44 
45 int main()
46 {
47     test_test<0>();
48     test_test<1>();
49     test_test<31>();
50     test_test<32>();
51     test_test<33>();
52     test_test<63>();
53     test_test<64>();
54     test_test<65>();
55     test_test<1000>();
56 }
57