Skip to content

Commit ca3f4a4

Browse files
authored
Merge pull request #326 from elbeno/empty-bitset-issue
🐛 Fix bitset construction
2 parents f1ab593 + 7951bef commit ca3f4a4

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

include/stdx/bitset.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ class bitset {
175175
for (auto &elem : storage) {
176176
elem = allbits;
177177
}
178-
storage.back() &= lastmask;
178+
if constexpr (N > 0) {
179+
storage.back() &= lastmask;
180+
}
179181
}
180182

181183
constexpr explicit bitset(std::string_view str, std::size_t pos = 0,

test/bitset.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,4 +516,6 @@ TEST_CASE("zero size bitset", "[bitset]") {
516516
CHECK(bs3.to<std::uint8_t>() == 0);
517517
bs3 >>= 1;
518518
CHECK(bs3.to<std::uint8_t>() == 0);
519+
bs3 = stdx::bitset<0>{stdx::all_bits};
520+
CHECK(bs3.to<std::uint8_t>() == 0);
519521
}

test/type_bitset.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <type_traits>
1111

1212
TEST_CASE("bitset size", "[type_bitset]") {
13+
STATIC_CHECK(stdx::type_bitset<>{}.size() == 0u);
1314
STATIC_CHECK(stdx::type_bitset<int>{}.size() == 1u);
1415
STATIC_CHECK(stdx::type_bitset<int, float>{}.size() == 2u);
1516
}

0 commit comments

Comments
 (0)