1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // template <class charT>
10 //     explicit bitset(const charT* str,
11 //                     typename basic_string<charT>::size_type n = basic_string<charT>::npos,
12 //                     charT zero = charT('0'), charT one = charT('1'));
13 
14 #include <bitset>
15 #include <cassert>
16 #include <algorithm> // for 'min' and 'max'
17 #include <stdexcept> // for 'invalid_argument'
18 
19 #include "test_macros.h"
20 
21 TEST_MSVC_DIAGNOSTIC_IGNORED(6294) // Ill-defined for-loop:  initial condition does not satisfy test.  Loop body not executed.
22 
23 template <std::size_t N>
test_char_pointer_ctor()24 void test_char_pointer_ctor()
25 {
26     {
27 #ifndef TEST_HAS_NO_EXCEPTIONS
28         try {
29             std::bitset<N> v("xxx1010101010xxxx");
30             assert(false);
31         }
32         catch (std::invalid_argument&) {}
33 #endif
34     }
35 
36     {
37     const char str[] = "1010101010";
38     std::bitset<N> v(str);
39     std::size_t M = std::min<std::size_t>(v.size(), 10);
40     for (std::size_t i = 0; i < M; ++i)
41         assert(v[i] == (str[M - 1 - i] == '1'));
42     for (std::size_t i = 10; i < v.size(); ++i)
43         assert(v[i] == false);
44     }
45 }
46 
main(int,char **)47 int main(int, char**)
48 {
49     test_char_pointer_ctor<0>();
50     test_char_pointer_ctor<1>();
51     test_char_pointer_ctor<31>();
52     test_char_pointer_ctor<32>();
53     test_char_pointer_ctor<33>();
54     test_char_pointer_ctor<63>();
55     test_char_pointer_ctor<64>();
56     test_char_pointer_ctor<65>();
57     test_char_pointer_ctor<1000>();
58 
59   return 0;
60 }
61