[libcxx-commits] [libcxx] Adds back special-case for booleans in std::variant gated by _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT. (PR #73121)
Jordan Rupprecht via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Nov 22 07:24:44 PST 2023
================
@@ -199,19 +204,23 @@ void test_construction_with_repeated_types() {
static_assert(std::is_constructible<V, Bar>::value, "");
}
+#if !defined(_LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT)
void test_vector_bool() {
std::vector<bool> vec = {true};
std::variant<bool, int> v = vec[0];
assert(v.index() == 0);
assert(std::get<0>(v) == true);
}
+#endif
int main(int, char**) {
test_T_ctor_basic();
test_T_ctor_noexcept();
test_T_ctor_sfinae();
test_no_narrowing_check_for_class_types();
test_construction_with_repeated_types();
+#if !defined(_LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT)
----------------
rupprecht wrote:
Instead of having multiple ifdefs, just have `test_vector_bool` always be defined, but possibly empty, i.e.
```cpp
void test_vector_bool() {
#ifndef _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT
std::vector<bool> vec = {true};
std::variant<bool, int> v = vec[0];
assert(v.index() == 0);
assert(std::get<0>(v) == true);
#endif // _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT
}
int main(int, char**) {
test_T_ctor_basic();
test_T_ctor_noexcept();
test_T_ctor_sfinae();
test_no_narrowing_check_for_class_types();
test_construction_with_repeated_types();
test_vector_bool();
```
https://github.com/llvm/llvm-project/pull/73121
More information about the libcxx-commits
mailing list