Skip to content

Commit 9e406ef

Browse files
authored
[libc++] Remove _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT (#83928)
This was slated for removal in LLVM 19.
1 parent 2037577 commit 9e406ef

File tree

7 files changed

+18
-72
lines changed

7 files changed

+18
-72
lines changed

libcxx/docs/ReleaseNotes/19.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Deprecations and Removals
6565
provided, and such a base template is bound to be incorrect for some types, which could currently cause unexpected behavior
6666
while going undetected.
6767

68-
- TODO: The ``_LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT`` macro that changed the behavior for narrowing conversions
68+
- The ``_LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT`` macro that changed the behavior for narrowing conversions
6969
in ``std::variant`` has been removed in LLVM 19.
7070

7171
- TODO: The ``_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS`` macro has been removed in LLVM 19.

libcxx/include/variant

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,13 @@ inline constexpr size_t variant_npos = static_cast<size_t>(-1);
347347

348348
template <size_t _NumAlternatives>
349349
_LIBCPP_HIDE_FROM_ABI constexpr auto __choose_index_type() {
350-
#ifdef _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
350+
# ifdef _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
351351
if constexpr (_NumAlternatives < numeric_limits<unsigned char>::max())
352352
return static_cast<unsigned char>(0);
353353
else if constexpr (_NumAlternatives < numeric_limits<unsigned short>::max())
354354
return static_cast<unsigned short>(0);
355355
else
356-
#endif // _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
356+
# endif // _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
357357
return static_cast<unsigned int>(0);
358358
}
359359

@@ -1085,38 +1085,16 @@ struct __narrowing_check {
10851085
};
10861086

10871087
template <class _Dest, class _Source>
1088-
using __check_for_narrowing _LIBCPP_NODEBUG = typename _If<
1089-
# ifdef _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT
1090-
false &&
1091-
# endif
1092-
is_arithmetic<_Dest>::value,
1093-
__narrowing_check,
1094-
__no_narrowing_check >::template _Apply<_Dest, _Source>;
1088+
using __check_for_narrowing _LIBCPP_NODEBUG =
1089+
typename _If< is_arithmetic<_Dest>::value, __narrowing_check, __no_narrowing_check >::template _Apply<_Dest,
1090+
_Source>;
10951091

10961092
template <class _Tp, size_t _Idx>
10971093
struct __overload {
10981094
template <class _Up>
10991095
auto operator()(_Tp, _Up&&) const -> __check_for_narrowing<_Tp, _Up>;
11001096
};
11011097

1102-
// TODO(LLVM-19): Remove all occurrences of this macro.
1103-
# ifdef _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT
1104-
template <class _Tp, size_t>
1105-
struct __overload_bool {
1106-
template <class _Up, class _Ap = __remove_cvref_t<_Up>>
1107-
auto operator()(bool, _Up&&) const -> enable_if_t<is_same_v<_Ap, bool>, __type_identity<_Tp>>;
1108-
};
1109-
1110-
template <size_t _Idx>
1111-
struct __overload<bool, _Idx> : __overload_bool<bool, _Idx> {};
1112-
template <size_t _Idx>
1113-
struct __overload<bool const, _Idx> : __overload_bool<bool const, _Idx> {};
1114-
template <size_t _Idx>
1115-
struct __overload<bool volatile, _Idx> : __overload_bool<bool volatile, _Idx> {};
1116-
template <size_t _Idx>
1117-
struct __overload<bool const volatile, _Idx> : __overload_bool<bool const volatile, _Idx> {};
1118-
# endif
1119-
11201098
template <class... _Bases>
11211099
struct __all_overloads : _Bases... {
11221100
void operator()() const;

libcxx/test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ void test_T_assignment_sfinae() {
134134
}
135135
{
136136
using V = std::variant<std::string, float>;
137-
static_assert(std::is_assignable<V, int>::value == VariantAllowsNarrowingConversions,
138-
"no matching operator=");
137+
static_assert(!std::is_assignable<V, int>::value, "no matching operator=");
139138
}
140139
{
141140
using V = std::variant<std::unique_ptr<int>, bool>;
@@ -144,12 +143,8 @@ void test_T_assignment_sfinae() {
144143
struct X {
145144
operator void*();
146145
};
147-
static_assert(!std::is_assignable<V, X>::value,
148-
"no boolean conversion in operator=");
149-
#ifndef _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT
150-
static_assert(std::is_assignable<V, std::false_type>::value,
151-
"converted to bool in operator=");
152-
#endif
146+
static_assert(!std::is_assignable<V, X>::value, "no boolean conversion in operator=");
147+
static_assert(std::is_assignable<V, std::false_type>::value, "converted to bool in operator=");
153148
}
154149
{
155150
struct X {};
@@ -188,7 +183,6 @@ void test_T_assignment_basic() {
188183
assert(v.index() == 1);
189184
assert(std::get<1>(v) == 43);
190185
}
191-
#ifndef TEST_VARIANT_ALLOWS_NARROWING_CONVERSIONS
192186
{
193187
std::variant<unsigned, long> v;
194188
v = 42;
@@ -198,7 +192,6 @@ void test_T_assignment_basic() {
198192
assert(v.index() == 0);
199193
assert(std::get<0>(v) == 43);
200194
}
201-
#endif
202195
{
203196
std::variant<std::string, bool> v = true;
204197
v = "bar";
@@ -299,13 +292,11 @@ void test_T_assignment_performs_assignment() {
299292
}
300293

301294
void test_T_assignment_vector_bool() {
302-
#ifndef _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT
303295
std::vector<bool> vec = {true};
304296
std::variant<bool, int> v;
305297
v = vec[0];
306298
assert(v.index() == 0);
307299
assert(std::get<0>(v) == true);
308-
#endif
309300
}
310301

311302
int main(int, char**) {

libcxx/test/std/utilities/variant/variant.variant/variant.assign/conv.pass.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,16 @@ int main(int, char**)
2525
{
2626
static_assert(!std::is_assignable<std::variant<int, int>, int>::value, "");
2727
static_assert(!std::is_assignable<std::variant<long, long long>, int>::value, "");
28-
static_assert(std::is_assignable<std::variant<char>, int>::value == VariantAllowsNarrowingConversions, "");
28+
static_assert(!std::is_assignable<std::variant<char>, int>::value, "");
2929

30-
static_assert(std::is_assignable<std::variant<std::string, float>, int>::value == VariantAllowsNarrowingConversions, "");
31-
static_assert(std::is_assignable<std::variant<std::string, double>, int>::value == VariantAllowsNarrowingConversions, "");
30+
static_assert(!std::is_assignable<std::variant<std::string, float>, int>::value, "");
31+
static_assert(!std::is_assignable<std::variant<std::string, double>, int>::value, "");
3232
static_assert(!std::is_assignable<std::variant<std::string, bool>, int>::value, "");
3333

3434
static_assert(!std::is_assignable<std::variant<int, bool>, decltype("meow")>::value, "");
3535
static_assert(!std::is_assignable<std::variant<int, const bool>, decltype("meow")>::value, "");
3636

37-
#ifndef _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT
3837
static_assert(std::is_assignable<std::variant<bool>, std::true_type>::value, "");
39-
#endif
4038
static_assert(!std::is_assignable<std::variant<bool>, std::unique_ptr<char> >::value, "");
4139
static_assert(!std::is_assignable<std::variant<bool>, decltype(nullptr)>::value, "");
4240

libcxx/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ void test_T_ctor_sfinae() {
6868
}
6969
{
7070
using V = std::variant<std::string, float>;
71-
static_assert(std::is_constructible<V, int>::value == VariantAllowsNarrowingConversions,
72-
"no matching constructor");
71+
static_assert(!std::is_constructible<V, int>::value, "no matching constructor");
7372
}
7473
{
7574
using V = std::variant<std::unique_ptr<int>, bool>;
@@ -78,12 +77,8 @@ void test_T_ctor_sfinae() {
7877
struct X {
7978
operator void*();
8079
};
81-
static_assert(!std::is_constructible<V, X>::value,
82-
"no boolean conversion in constructor");
83-
#ifndef _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT
84-
static_assert(std::is_constructible<V, std::false_type>::value,
85-
"converted to bool in constructor");
86-
#endif
80+
static_assert(!std::is_constructible<V, X>::value, "no boolean conversion in constructor");
81+
static_assert(std::is_constructible<V, std::false_type>::value, "converted to bool in constructor");
8782
}
8883
{
8984
struct X {};
@@ -128,13 +123,11 @@ void test_T_ctor_basic() {
128123
static_assert(v.index() == 1, "");
129124
static_assert(std::get<1>(v) == 42, "");
130125
}
131-
#ifndef TEST_VARIANT_ALLOWS_NARROWING_CONVERSIONS
132126
{
133127
constexpr std::variant<unsigned, long> v(42);
134128
static_assert(v.index() == 1, "");
135129
static_assert(std::get<1>(v) == 42, "");
136130
}
137-
#endif
138131
{
139132
std::variant<std::string, bool const> v = "foo";
140133
assert(v.index() == 0);
@@ -202,12 +195,10 @@ void test_construction_with_repeated_types() {
202195
}
203196

204197
void test_vector_bool() {
205-
#ifndef _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT
206198
std::vector<bool> vec = {true};
207199
std::variant<bool, int> v = vec[0];
208200
assert(v.index() == 0);
209201
assert(std::get<0>(v) == true);
210-
#endif
211202
}
212203

213204
int main(int, char**) {

libcxx/test/std/utilities/variant/variant.variant/variant.ctor/conv.pass.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,16 @@ int main(int, char**)
2424
{
2525
static_assert(!std::is_constructible<std::variant<int, int>, int>::value, "");
2626
static_assert(!std::is_constructible<std::variant<long, long long>, int>::value, "");
27-
static_assert(std::is_constructible<std::variant<char>, int>::value == VariantAllowsNarrowingConversions, "");
27+
static_assert(!std::is_constructible<std::variant<char>, int>::value, "");
2828

29-
static_assert(std::is_constructible<std::variant<std::string, float>, int>::value == VariantAllowsNarrowingConversions, "");
30-
static_assert(std::is_constructible<std::variant<std::string, double>, int>::value == VariantAllowsNarrowingConversions, "");
29+
static_assert(!std::is_constructible<std::variant<std::string, float>, int>::value, "");
30+
static_assert(!std::is_constructible<std::variant<std::string, double>, int>::value, "");
3131
static_assert(!std::is_constructible<std::variant<std::string, bool>, int>::value, "");
3232

3333
static_assert(!std::is_constructible<std::variant<int, bool>, decltype("meow")>::value, "");
3434
static_assert(!std::is_constructible<std::variant<int, const bool>, decltype("meow")>::value, "");
3535

36-
#ifndef _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT
3736
static_assert(std::is_constructible<std::variant<bool>, std::true_type>::value, "");
38-
#endif
3937
static_assert(!std::is_constructible<std::variant<bool>, std::unique_ptr<char> >::value, "");
4038
static_assert(!std::is_constructible<std::variant<bool>, decltype(nullptr)>::value, "");
4139

libcxx/test/support/variant_test_helpers.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@
2424
// FIXME: Currently the variant<T&> tests are disabled using this macro.
2525
#define TEST_VARIANT_HAS_NO_REFERENCES
2626

27-
// TODO(LLVM-19): Remove TEST_VARIANT_ALLOWS_NARROWING_CONVERSIONS
28-
#ifdef _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT
29-
# define TEST_VARIANT_ALLOWS_NARROWING_CONVERSIONS
30-
#endif
31-
#ifdef TEST_VARIANT_ALLOWS_NARROWING_CONVERSIONS
32-
constexpr bool VariantAllowsNarrowingConversions = true;
33-
#else
34-
constexpr bool VariantAllowsNarrowingConversions = false;
35-
#endif
36-
3727
#ifndef TEST_HAS_NO_EXCEPTIONS
3828
struct CopyThrows {
3929
CopyThrows() = default;

0 commit comments

Comments
 (0)