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// template <class charT>
12//     explicit bitset(const charT* str,
13//                     typename basic_string<charT>::size_type n = basic_string<charT>::npos,
14//                     charT zero = charT('0'), charT one = charT('1'));
15
16#include <bitset>
17#include <cassert>
18#include <algorithm> // for 'min' and 'max'
19#include <stdexcept> // for 'invalid_argument'
20
21#if defined(__clang__)
22#pragma clang diagnostic ignored "-Wtautological-compare"
23#endif
24
25template <std::size_t N>
26void test_char_pointer_ctor()
27{
28    {
29    try
30    {
31        std::bitset<N> v("xxx1010101010xxxx");
32        assert(false);
33    }
34    catch (std::invalid_argument&)
35    {
36    }
37    }
38
39    {
40    const char str[] ="1010101010";
41    std::bitset<N> v(str);
42    std::size_t M = std::min<std::size_t>(N, 10);
43    for (std::size_t i = 0; i < M; ++i)
44        assert(v[i] == (str[M - 1 - i] == '1'));
45    for (std::size_t i = 10; i < N; ++i)
46        assert(v[i] == false);
47    }
48}
49
50int main()
51{
52    test_char_pointer_ctor<0>();
53    test_char_pointer_ctor<1>();
54    test_char_pointer_ctor<31>();
55    test_char_pointer_ctor<32>();
56    test_char_pointer_ctor<33>();
57    test_char_pointer_ctor<63>();
58    test_char_pointer_ctor<64>();
59    test_char_pointer_ctor<65>();
60    test_char_pointer_ctor<1000>();
61}
62