Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion stl/inc/bitset
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ public:
_Construct<_Traits>(_Str.data() + _Pos, _Count, _Elem0, _Elem1);
}

template <class _Elem>
template <class _Elem, enable_if_t<conjunction_v<negation<is_array<_Elem>>, is_trivially_copyable<_Elem>,
is_standard_layout<_Elem>, is_trivially_default_constructible<_Elem>>,
int> = 0>
_CONSTEXPR23 explicit bitset(const _Elem* _Ntcts,
typename basic_string<_Elem>::size_type _Count = basic_string<_Elem>::npos,
_Elem _Elem0 = static_cast<_Elem>('0'), _Elem _Elem1 = static_cast<_Elem>('1')) {
Expand Down
3 changes: 0 additions & 3 deletions tests/libcxx/expected_results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ std/input.output/iostreams.base/ios.base/ios.base.storage/pword.pass.cpp SKIPPED
# LWG-3197 "std::prev should not require BidirectionalIterator" (New)
std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp FAIL

# Testing nonstandard behavior
std/utilities/template.bitset/bitset.cons/string_ctor.pass.cpp FAIL

# Tests with undefined behavior under N4842 [basic.start.term]/6 (detached threads)
std/thread/futures/futures.task/futures.task.members/dtor.pass.cpp SKIPPED
std/thread/futures/futures.unique_future/wait_until.pass.cpp SKIPPED
Expand Down
95 changes: 95 additions & 0 deletions tests/std/tests/Dev10_860410_bitset_ctors/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cstdlib>
#include <stdexcept>
#include <string>
#include <type_traits>

using namespace std;

Expand All @@ -31,6 +32,100 @@ namespace lwg_4140 {
}
} // namespace lwg_4140

// Also test LWG-4294 "bitset(const CharT*) constructor needs to be constrained".

template <size_t Len, class Elem, bool Expected>
void test_ntcts_constructibility_single() { // COMPILE-ONLY
STATIC_ASSERT(is_constructible_v<bitset<Len>, Elem*, size_t, Elem, Elem> == Expected);
STATIC_ASSERT(is_constructible_v<bitset<Len>, const Elem*, size_t, Elem, Elem> == Expected);
// the constructor is explicit
STATIC_ASSERT(!is_convertible_v<Elem*, bitset<Len>>);
STATIC_ASSERT(!is_convertible_v<const Elem*, bitset<Len>>);
}

template <class Elem, bool Expected>
void test_ntcts_constructibility_for_lengths() { // COMPILE-ONLY
test_ntcts_constructibility_single<0, Elem, Expected>();
test_ntcts_constructibility_single<1, Elem, Expected>();
test_ntcts_constructibility_single<8, Elem, Expected>();
test_ntcts_constructibility_single<16, Elem, Expected>();
test_ntcts_constructibility_single<32, Elem, Expected>();
test_ntcts_constructibility_single<48, Elem, Expected>();
test_ntcts_constructibility_single<64, Elem, Expected>();
test_ntcts_constructibility_single<96, Elem, Expected>();
}

void test_ntcts_constructibility() { // COMPILE-ONLY
// test encoded character types (expected usages)
test_ntcts_constructibility_for_lengths<char, true>();
#ifdef __cpp_char8_t
test_ntcts_constructibility_for_lengths<char8_t, true>();
#endif // __cpp_char8_t
test_ntcts_constructibility_for_lengths<char16_t, true>();
test_ntcts_constructibility_for_lengths<char32_t, true>();
test_ntcts_constructibility_for_lengths<wchar_t, true>();

enum unscoped_enum {};
enum class scoped_enum {};

struct pod_class {
int n1;
};
struct missing_trivial_default_ctor {
int n2 = 42;
};
struct missing_standard_layout : pod_class {
int n3;
};
struct missing_trivially_copyable {
missing_trivially_copyable() = default;
missing_trivially_copyable(const missing_trivially_copyable&) = default;
missing_trivially_copyable(missing_trivially_copyable&&) = default;
missing_trivially_copyable& operator=(const missing_trivially_copyable&) = default;
constexpr missing_trivially_copyable& operator=(missing_trivially_copyable&&) noexcept {
return *this;
}
~missing_trivially_copyable() = default;
};

// test scalar types
test_ntcts_constructibility_for_lengths<int, true>();
test_ntcts_constructibility_for_lengths<char*, true>();
test_ntcts_constructibility_for_lengths<void (*)(), true>();
test_ntcts_constructibility_for_lengths<unscoped_enum, true>();
test_ntcts_constructibility_for_lengths<scoped_enum, true>();
test_ntcts_constructibility_for_lengths<int missing_trivial_default_ctor::*, true>();
test_ntcts_constructibility_for_lengths<void (missing_standard_layout::*)() const&, true>();

// test POD array types
test_ntcts_constructibility_for_lengths<char[1], false>();
test_ntcts_constructibility_for_lengths<char[1][2], false>();
#ifdef __cpp_char8_t
test_ntcts_constructibility_for_lengths<char8_t[2], false>();
test_ntcts_constructibility_for_lengths<char8_t[2][4], false>();
#endif // __cpp_char8_t
test_ntcts_constructibility_for_lengths<char16_t[3], false>();
test_ntcts_constructibility_for_lengths<char16_t[3][6], false>();
test_ntcts_constructibility_for_lengths<char32_t[4], false>();
test_ntcts_constructibility_for_lengths<char32_t[4][8], false>();
test_ntcts_constructibility_for_lengths<wchar_t[5], false>();
test_ntcts_constructibility_for_lengths<wchar_t[5][10], false>();
test_ntcts_constructibility_for_lengths<int[6], false>();
test_ntcts_constructibility_for_lengths<int[6][12][3], false>();
test_ntcts_constructibility_for_lengths<char* [7], false>();
test_ntcts_constructibility_for_lengths<char* [7][1][2][14], false>();

// test class types
test_ntcts_constructibility_for_lengths<pod_class, true>();
test_ntcts_constructibility_for_lengths<missing_trivial_default_ctor, false>();
test_ntcts_constructibility_for_lengths<missing_standard_layout, false>();
test_ntcts_constructibility_for_lengths<missing_trivially_copyable, false>();

// test worse class types
test_ntcts_constructibility_for_lengths<string, false>();
test_ntcts_constructibility_for_lengths<invalid_argument, false>();
}

const char parsedStr[] = "1000110111110011110111111111111111010111110111100101010100001001"
"1111111111111111111111111111111111111111111111111111111111111111"
"0111111111111111111111111111111111111111111111111111111111111111"
Expand Down