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 // test bitset<N>& operator|=(const bitset<N>& rhs);
10 
11 #include <bitset>
12 #include <cstdlib>
13 #include <cassert>
14 
15 #include "test_macros.h"
16 
17 #if defined(TEST_COMPILER_CLANG)
18 #pragma clang diagnostic ignored "-Wtautological-compare"
19 #elif defined(TEST_COMPILER_C1XX)
20 #pragma warning(disable: 6294) // Ill-defined for-loop:  initial condition does not satisfy test.  Loop body not executed.
21 #endif
22 
23 template <std::size_t N>
24 std::bitset<N>
make_bitset()25 make_bitset()
26 {
27     std::bitset<N> v;
28     for (std::size_t i = 0; i < N; ++i)
29         v[i] = static_cast<bool>(std::rand() & 1);
30     return v;
31 }
32 
33 template <std::size_t N>
test_op_or_eq()34 void test_op_or_eq()
35 {
36     std::bitset<N> v1 = make_bitset<N>();
37     std::bitset<N> v2 = make_bitset<N>();
38     std::bitset<N> v3 = v1;
39     v1 |= v2;
40     for (std::size_t i = 0; i < N; ++i)
41         assert(v1[i] == (v3[i] || v2[i]));
42 }
43 
main(int,char **)44 int main(int, char**)
45 {
46     test_op_or_eq<0>();
47     test_op_or_eq<1>();
48     test_op_or_eq<31>();
49     test_op_or_eq<32>();
50     test_op_or_eq<33>();
51     test_op_or_eq<63>();
52     test_op_or_eq<64>();
53     test_op_or_eq<65>();
54     test_op_or_eq<1000>();
55 
56   return 0;
57 }
58