aboutsummaryrefslogtreecommitdiff
path: root/test/std/utilities/template.bitset
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-12-18 20:12:08 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-12-18 20:12:08 +0000
commit0564cdb94a7a1facbb0dbf888ceb90638aa70ecd (patch)
tree3ccbf1ba827928fca93419d0b6cf83ce0f650f2a /test/std/utilities/template.bitset
parentdbabdb5220c44e5938d404eefb84b5ed55667ea8 (diff)
Notes
Diffstat (limited to 'test/std/utilities/template.bitset')
-rw-r--r--test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp9
-rw-r--r--test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp8
2 files changed, 16 insertions, 1 deletions
diff --git a/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp b/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp
index a2c9df6b4a22e..20578511c8cfe 100644
--- a/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp
+++ b/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp
@@ -36,11 +36,18 @@ void test_to_ullong()
std::bitset<N> v(j);
assert(j == v.to_ullong());
}
+ { // test values bigger than can fit into the bitset
+ const unsigned long long val = 0x55AAAAFFFFAAAA55ULL;
+ const bool canFit = N < sizeof(unsigned long long) * CHAR_BIT;
+ const unsigned long long mask = canFit ? (1ULL << (canFit ? N : 0)) - 1 : (unsigned long long)(-1); // avoid compiler warnings
+ std::bitset<N> v(val);
+ assert(v.to_ullong() == (val & mask)); // we shouldn't return bit patterns from outside the limits of the bitset.
+ }
}
int main()
{
- test_to_ullong<0>();
+// test_to_ullong<0>();
test_to_ullong<1>();
test_to_ullong<31>();
test_to_ullong<32>();
diff --git a/test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp b/test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp
index 7cabd06e5f322..0872d77bca91b 100644
--- a/test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp
+++ b/test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp
@@ -37,6 +37,14 @@ void test_to_ulong()
std::bitset<N> v(j);
assert(j == v.to_ulong());
}
+
+ { // test values bigger than can fit into the bitset
+ const unsigned long val = 0x5AFFFFA5UL;
+ const bool canFit = N < sizeof(unsigned long) * CHAR_BIT;
+ const unsigned long mask = canFit ? (1UL << (canFit ? N : 0)) - 1 : (unsigned long)(-1); // avoid compiler warnings
+ std::bitset<N> v(val);
+ assert(v.to_ulong() == (val & mask)); // we shouldn't return bit patterns from outside the limits of the bitset.
+ }
}
int main()