[libcxx-commits] [libcxx] [libc++][test] remove tests that testing std::variant<T&> (PR #84222)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 7 00:41:16 PST 2024
https://github.com/huixie90 updated https://github.com/llvm/llvm-project/pull/84222
>From 17ac84d863ef184e0df78e01628268e7b2e1d5ca Mon Sep 17 00:00:00 2001
From: Hui <hui.xie0621 at gmail.com>
Date: Wed, 6 Mar 2024 19:12:32 +0000
Subject: [PATCH 1/2] [libc++][test] remove tests that testing std::variant<T&>
---
.../variant/variant.get/get_if_index.pass.cpp | 54 --------
.../variant/variant.get/get_if_type.pass.cpp | 55 --------
.../variant/variant.get/get_index.pass.cpp | 121 -----------------
.../variant/variant.get/get_type.pass.cpp | 125 ------------------
.../variant_alternative.pass.cpp | 10 --
.../variant.variant/variant.assign/T.pass.cpp | 29 ----
.../variant.variant/variant.ctor/T.pass.cpp | 28 ----
.../variant.ctor/default.pass.cpp | 6 -
.../variant.mod/emplace_index_args.pass.cpp | 58 --------
.../variant.mod/emplace_type_args.pass.cpp | 59 ---------
.../variant.visit.member/visit.pass.cpp | 33 -----
.../visit_return_type.pass.cpp | 32 -----
.../variant/variant.visit/visit.pass.cpp | 30 -----
.../variant.visit/visit_return_type.pass.cpp | 30 -----
libcxx/test/support/variant_test_helpers.h | 3 -
15 files changed, 673 deletions(-)
diff --git a/libcxx/test/std/utilities/variant/variant.get/get_if_index.pass.cpp b/libcxx/test/std/utilities/variant/variant.get/get_if_index.pass.cpp
index 3333d2a993ec98..6b923905b7530f 100644
--- a/libcxx/test/std/utilities/variant/variant.get/get_if_index.pass.cpp
+++ b/libcxx/test/std/utilities/variant/variant.get/get_if_index.pass.cpp
@@ -44,30 +44,6 @@ void test_const_get_if() {
static_assert(*std::get_if<1>(&v) == 42, "");
static_assert(std::get_if<0>(&v) == nullptr, "");
}
-// FIXME: Remove these once reference support is reinstated
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int &>;
- int x = 42;
- const V v(x);
- ASSERT_SAME_TYPE(decltype(std::get_if<0>(&v)), int *);
- assert(std::get_if<0>(&v) == &x);
- }
- {
- using V = std::variant<int &&>;
- int x = 42;
- const V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get_if<0>(&v)), int *);
- assert(std::get_if<0>(&v) == &x);
- }
- {
- using V = std::variant<const int &&>;
- int x = 42;
- const V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get_if<0>(&v)), const int *);
- assert(std::get_if<0>(&v) == &x);
- }
-#endif
}
void test_get_if() {
@@ -92,36 +68,6 @@ void test_get_if() {
assert(std::get_if<0>(&v) == nullptr);
}
// FIXME: Remove these once reference support is reinstated
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int &>;
- int x = 42;
- V v(x);
- ASSERT_SAME_TYPE(decltype(std::get_if<0>(&v)), int *);
- assert(std::get_if<0>(&v) == &x);
- }
- {
- using V = std::variant<const int &>;
- int x = 42;
- V v(x);
- ASSERT_SAME_TYPE(decltype(std::get_if<0>(&v)), const int *);
- assert(std::get_if<0>(&v) == &x);
- }
- {
- using V = std::variant<int &&>;
- int x = 42;
- V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get_if<0>(&v)), int *);
- assert(std::get_if<0>(&v) == &x);
- }
- {
- using V = std::variant<const int &&>;
- int x = 42;
- V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get_if<0>(&v)), const int *);
- assert(std::get_if<0>(&v) == &x);
- }
-#endif
}
int main(int, char**) {
diff --git a/libcxx/test/std/utilities/variant/variant.get/get_if_type.pass.cpp b/libcxx/test/std/utilities/variant/variant.get/get_if_type.pass.cpp
index b81e000f5bf6c3..c4fefc74e62a9c 100644
--- a/libcxx/test/std/utilities/variant/variant.get/get_if_type.pass.cpp
+++ b/libcxx/test/std/utilities/variant/variant.get/get_if_type.pass.cpp
@@ -42,30 +42,6 @@ void test_const_get_if() {
static_assert(*std::get_if<const long>(&v) == 42, "");
static_assert(std::get_if<int>(&v) == nullptr, "");
}
-// FIXME: Remove these once reference support is reinstated
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int &>;
- int x = 42;
- const V v(x);
- ASSERT_SAME_TYPE(decltype(std::get_if<int &>(&v)), int *);
- assert(std::get_if<int &>(&v) == &x);
- }
- {
- using V = std::variant<int &&>;
- int x = 42;
- const V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get_if<int &&>(&v)), int *);
- assert(std::get_if<int &&>(&v) == &x);
- }
- {
- using V = std::variant<const int &&>;
- int x = 42;
- const V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get_if<const int &&>(&v)), const int *);
- assert(std::get_if<const int &&>(&v) == &x);
- }
-#endif
}
void test_get_if() {
@@ -89,37 +65,6 @@ void test_get_if() {
assert(*std::get_if<const long>(&v) == 42);
assert(std::get_if<int>(&v) == nullptr);
}
-// FIXME: Remove these once reference support is reinstated
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int &>;
- int x = 42;
- V v(x);
- ASSERT_SAME_TYPE(decltype(std::get_if<int &>(&v)), int *);
- assert(std::get_if<int &>(&v) == &x);
- }
- {
- using V = std::variant<const int &>;
- int x = 42;
- V v(x);
- ASSERT_SAME_TYPE(decltype(std::get_if<const int &>(&v)), const int *);
- assert(std::get_if<const int &>(&v) == &x);
- }
- {
- using V = std::variant<int &&>;
- int x = 42;
- V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get_if<int &&>(&v)), int *);
- assert(std::get_if<int &&>(&v) == &x);
- }
- {
- using V = std::variant<const int &&>;
- int x = 42;
- V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get_if<const int &&>(&v)), const int *);
- assert(std::get_if<const int &&>(&v) == &x);
- }
-#endif
}
int main(int, char**) {
diff --git a/libcxx/test/std/utilities/variant/variant.get/get_index.pass.cpp b/libcxx/test/std/utilities/variant/variant.get/get_index.pass.cpp
index 97c7ff0ed09579..7ec9d8827f6b4b 100644
--- a/libcxx/test/std/utilities/variant/variant.get/get_index.pass.cpp
+++ b/libcxx/test/std/utilities/variant/variant.get/get_index.pass.cpp
@@ -60,30 +60,6 @@ void test_const_lvalue_get() {
ASSERT_SAME_TYPE(decltype(std::get<1>(v)), const long &);
assert(std::get<1>(v) == 42);
}
-// FIXME: Remove these once reference support is reinstated
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int &>;
- int x = 42;
- const V v(x);
- ASSERT_SAME_TYPE(decltype(std::get<0>(v)), int &);
- assert(&std::get<0>(v) == &x);
- }
- {
- using V = std::variant<int &&>;
- int x = 42;
- const V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get<0>(v)), int &);
- assert(&std::get<0>(v) == &x);
- }
- {
- using V = std::variant<const int &&>;
- int x = 42;
- const V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get<0>(v)), const int &);
- assert(&std::get<0>(v) == &x);
- }
-#endif
}
void test_lvalue_get() {
@@ -100,37 +76,6 @@ void test_lvalue_get() {
ASSERT_SAME_TYPE(decltype(std::get<1>(v)), const long &);
assert(std::get<1>(v) == 42);
}
-// FIXME: Remove these once reference support is reinstated
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int &>;
- int x = 42;
- V v(x);
- ASSERT_SAME_TYPE(decltype(std::get<0>(v)), int &);
- assert(&std::get<0>(v) == &x);
- }
- {
- using V = std::variant<const int &>;
- int x = 42;
- V v(x);
- ASSERT_SAME_TYPE(decltype(std::get<0>(v)), const int &);
- assert(&std::get<0>(v) == &x);
- }
- {
- using V = std::variant<int &&>;
- int x = 42;
- V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get<0>(v)), int &);
- assert(&std::get<0>(v) == &x);
- }
- {
- using V = std::variant<const int &&>;
- int x = 42;
- V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get<0>(v)), const int &);
- assert(&std::get<0>(v) == &x);
- }
-#endif
}
void test_rvalue_get() {
@@ -147,39 +92,6 @@ void test_rvalue_get() {
ASSERT_SAME_TYPE(decltype(std::get<1>(std::move(v))), const long &&);
assert(std::get<1>(std::move(v)) == 42);
}
-// FIXME: Remove these once reference support is reinstated
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int &>;
- int x = 42;
- V v(x);
- ASSERT_SAME_TYPE(decltype(std::get<0>(std::move(v))), int &);
- assert(&std::get<0>(std::move(v)) == &x);
- }
- {
- using V = std::variant<const int &>;
- int x = 42;
- V v(x);
- ASSERT_SAME_TYPE(decltype(std::get<0>(std::move(v))), const int &);
- assert(&std::get<0>(std::move(v)) == &x);
- }
- {
- using V = std::variant<int &&>;
- int x = 42;
- V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get<0>(std::move(v))), int &&);
- int &&xref = std::get<0>(std::move(v));
- assert(&xref == &x);
- }
- {
- using V = std::variant<const int &&>;
- int x = 42;
- V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get<0>(std::move(v))), const int &&);
- const int &&xref = std::get<0>(std::move(v));
- assert(&xref == &x);
- }
-#endif
}
void test_const_rvalue_get() {
@@ -196,39 +108,6 @@ void test_const_rvalue_get() {
ASSERT_SAME_TYPE(decltype(std::get<1>(std::move(v))), const long &&);
assert(std::get<1>(std::move(v)) == 42);
}
-// FIXME: Remove these once reference support is reinstated
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int &>;
- int x = 42;
- const V v(x);
- ASSERT_SAME_TYPE(decltype(std::get<0>(std::move(v))), int &);
- assert(&std::get<0>(std::move(v)) == &x);
- }
- {
- using V = std::variant<const int &>;
- int x = 42;
- const V v(x);
- ASSERT_SAME_TYPE(decltype(std::get<0>(std::move(v))), const int &);
- assert(&std::get<0>(std::move(v)) == &x);
- }
- {
- using V = std::variant<int &&>;
- int x = 42;
- const V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get<0>(std::move(v))), int &&);
- int &&xref = std::get<0>(std::move(v));
- assert(&xref == &x);
- }
- {
- using V = std::variant<const int &&>;
- int x = 42;
- const V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get<0>(std::move(v))), const int &&);
- const int &&xref = std::get<0>(std::move(v));
- assert(&xref == &x);
- }
-#endif
}
template <std::size_t I> using Idx = std::integral_constant<std::size_t, I>;
diff --git a/libcxx/test/std/utilities/variant/variant.get/get_type.pass.cpp b/libcxx/test/std/utilities/variant/variant.get/get_type.pass.cpp
index d5e54d41e2f7b4..3485122c98f0b1 100644
--- a/libcxx/test/std/utilities/variant/variant.get/get_type.pass.cpp
+++ b/libcxx/test/std/utilities/variant/variant.get/get_type.pass.cpp
@@ -54,30 +54,6 @@ void test_const_lvalue_get() {
ASSERT_SAME_TYPE(decltype(std::get<const long>(v)), const long &);
assert(std::get<const long>(v) == 42);
}
-// FIXME: Remove these once reference support is reinstated
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int &>;
- int x = 42;
- const V v(x);
- ASSERT_SAME_TYPE(decltype(std::get<int &>(v)), int &);
- assert(&std::get<int &>(v) == &x);
- }
- {
- using V = std::variant<int &&>;
- int x = 42;
- const V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get<int &&>(v)), int &);
- assert(&std::get<int &&>(v) == &x);
- }
- {
- using V = std::variant<const int &&>;
- int x = 42;
- const V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get<const int &&>(v)), const int &);
- assert(&std::get<const int &&>(v) == &x);
- }
-#endif
}
void test_lvalue_get() {
@@ -94,37 +70,6 @@ void test_lvalue_get() {
ASSERT_SAME_TYPE(decltype(std::get<const long>(v)), const long &);
assert(std::get<const long>(v) == 42);
}
-// FIXME: Remove these once reference support is reinstated
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int &>;
- int x = 42;
- V v(x);
- ASSERT_SAME_TYPE(decltype(std::get<int &>(v)), int &);
- assert(&std::get<int &>(v) == &x);
- }
- {
- using V = std::variant<const int &>;
- int x = 42;
- V v(x);
- ASSERT_SAME_TYPE(decltype(std::get<const int &>(v)), const int &);
- assert(&std::get<const int &>(v) == &x);
- }
- {
- using V = std::variant<int &&>;
- int x = 42;
- V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get<int &&>(v)), int &);
- assert(&std::get<int &&>(v) == &x);
- }
- {
- using V = std::variant<const int &&>;
- int x = 42;
- V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get<const int &&>(v)), const int &);
- assert(&std::get<const int &&>(v) == &x);
- }
-#endif
}
void test_rvalue_get() {
@@ -142,41 +87,6 @@ void test_rvalue_get() {
const long &&);
assert(std::get<const long>(std::move(v)) == 42);
}
-// FIXME: Remove these once reference support is reinstated
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int &>;
- int x = 42;
- V v(x);
- ASSERT_SAME_TYPE(decltype(std::get<int &>(std::move(v))), int &);
- assert(&std::get<int &>(std::move(v)) == &x);
- }
- {
- using V = std::variant<const int &>;
- int x = 42;
- V v(x);
- ASSERT_SAME_TYPE(decltype(std::get<const int &>(std::move(v))),
- const int &);
- assert(&std::get<const int &>(std::move(v)) == &x);
- }
- {
- using V = std::variant<int &&>;
- int x = 42;
- V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get<int &&>(std::move(v))), int &&);
- int &&xref = std::get<int &&>(std::move(v));
- assert(&xref == &x);
- }
- {
- using V = std::variant<const int &&>;
- int x = 42;
- V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get<const int &&>(std::move(v))),
- const int &&);
- const int &&xref = std::get<const int &&>(std::move(v));
- assert(&xref == &x);
- }
-#endif
}
void test_const_rvalue_get() {
@@ -194,41 +104,6 @@ void test_const_rvalue_get() {
const long &&);
assert(std::get<const long>(std::move(v)) == 42);
}
-// FIXME: Remove these once reference support is reinstated
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int &>;
- int x = 42;
- const V v(x);
- ASSERT_SAME_TYPE(decltype(std::get<int &>(std::move(v))), int &);
- assert(&std::get<int &>(std::move(v)) == &x);
- }
- {
- using V = std::variant<const int &>;
- int x = 42;
- const V v(x);
- ASSERT_SAME_TYPE(decltype(std::get<const int &>(std::move(v))),
- const int &);
- assert(&std::get<const int &>(std::move(v)) == &x);
- }
- {
- using V = std::variant<int &&>;
- int x = 42;
- const V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get<int &&>(std::move(v))), int &&);
- int &&xref = std::get<int &&>(std::move(v));
- assert(&xref == &x);
- }
- {
- using V = std::variant<const int &&>;
- int x = 42;
- const V v(std::move(x));
- ASSERT_SAME_TYPE(decltype(std::get<const int &&>(std::move(v))),
- const int &&);
- const int &&xref = std::get<const int &&>(std::move(v));
- assert(&xref == &x);
- }
-#endif
}
template <class Tp> struct identity { using type = Tp; };
diff --git a/libcxx/test/std/utilities/variant/variant.helpers/variant_alternative.pass.cpp b/libcxx/test/std/utilities/variant/variant.helpers/variant_alternative.pass.cpp
index be1a0c960d1cee..31b9b76213c45c 100644
--- a/libcxx/test/std/utilities/variant/variant.helpers/variant_alternative.pass.cpp
+++ b/libcxx/test/std/utilities/variant/variant.helpers/variant_alternative.pass.cpp
@@ -62,16 +62,6 @@ int main(int, char**) {
test<V, 2, const void *>();
test<V, 3, long double>();
}
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int, int &, const int &, int &&, long double>;
- test<V, 0, int>();
- test<V, 1, int &>();
- test<V, 2, const int &>();
- test<V, 3, int &&>();
- test<V, 4, long double>();
- }
-#endif
return 0;
}
diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp
index b3fc2021a6b223..4e8cb5eb183924 100644
--- a/libcxx/test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp
+++ b/libcxx/test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp
@@ -160,16 +160,6 @@ void test_T_assignment_sfinae() {
static_assert(std::is_assignable<V, Y>::value,
"regression on user-defined conversions in operator=");
}
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int, int &&>;
- static_assert(!std::is_assignable<V, int>::value, "ambiguous");
- }
- {
- using V = std::variant<int, const int &>;
- static_assert(!std::is_assignable<V, int>::value, "ambiguous");
- }
-#endif // TEST_VARIANT_HAS_NO_REFERENCES
}
void test_T_assignment_basic() {
@@ -211,25 +201,6 @@ void test_T_assignment_basic() {
assert(v.index() == 1);
assert(std::get<1>(v) == nullptr);
}
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int &, int &&, long>;
- int x = 42;
- V v(43l);
- v = x;
- assert(v.index() == 0);
- assert(&std::get<0>(v) == &x);
- v = std::move(x);
- assert(v.index() == 1);
- assert(&std::get<1>(v) == &x);
- // 'long' is selected by FUN(const int &) since 'const int &' cannot bind
- // to 'int&'.
- const int &cx = x;
- v = cx;
- assert(v.index() == 2);
- assert(std::get<2>(v) == 42);
- }
-#endif // TEST_VARIANT_HAS_NO_REFERENCES
}
void test_T_assignment_performs_construction() {
diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp
index 89fd646878eeca..f291fed12dade1 100644
--- a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp
+++ b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp
@@ -105,16 +105,6 @@ void test_T_ctor_sfinae() {
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int, int &&>;
- static_assert(!std::is_constructible<V, int>::value, "ambiguous");
- }
- {
- using V = std::variant<int, const int &>;
- static_assert(!std::is_constructible<V, int>::value, "ambiguous");
- }
-#endif
}
void test_T_ctor_basic() {
@@ -158,24 +148,6 @@ void test_T_ctor_basic() {
std::variant<RValueConvertibleFrom<int>, AnyConstructible> v2 = x;
assert(v2.index() == 1);
}
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<const int &, int &&, long>;
- static_assert(std::is_convertible<int &, V>::value, "must be implicit");
- int x = 42;
- V v(x);
- assert(v.index() == 0);
- assert(&std::get<0>(v) == &x);
- }
- {
- using V = std::variant<const int &, int &&, long>;
- static_assert(std::is_convertible<int, V>::value, "must be implicit");
- int x = 42;
- V v(std::move(x));
- assert(v.index() == 1);
- assert(&std::get<1>(v) == &x);
- }
-#endif
}
struct BoomOnAnything {
diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/default.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/default.pass.cpp
index cc1a3fe8ff78af..40db038a003366 100644
--- a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/default.pass.cpp
+++ b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/default.pass.cpp
@@ -44,12 +44,6 @@ void test_default_ctor_sfinae() {
using V = std::variant<NonDefaultConstructible, int>;
static_assert(!std::is_default_constructible<V>::value, "");
}
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int &, int>;
- static_assert(!std::is_default_constructible<V>::value, "");
- }
-#endif
}
void test_default_ctor_noexcept() {
diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.mod/emplace_index_args.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.mod/emplace_index_args.pass.cpp
index 96fcd7e7bee481..2fe9033dd8166f 100644
--- a/libcxx/test/std/utilities/variant/variant.variant/variant.mod/emplace_index_args.pass.cpp
+++ b/libcxx/test/std/utilities/variant/variant.variant/variant.mod/emplace_index_args.pass.cpp
@@ -55,29 +55,6 @@ void test_emplace_sfinae() {
static_assert(emplace_exists<V, 2, int *>(), "");
static_assert(!emplace_exists<V, 3>(), "cannot construct");
}
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int, int &, const int &, int &&, TestTypes::NoCtors>;
- static_assert(emplace_exists<V, 0>(), "");
- static_assert(emplace_exists<V, 0, int>(), "");
- static_assert(emplace_exists<V, 0, long long>(), "");
- static_assert(!emplace_exists<V, 0, int, int>(), "too many args");
- static_assert(emplace_exists<V, 1, int &>(), "");
- static_assert(!emplace_exists<V, 1>(), "cannot default construct ref");
- static_assert(!emplace_exists<V, 1, const int &>(), "cannot bind ref");
- static_assert(!emplace_exists<V, 1, int &&>(), "cannot bind ref");
- static_assert(emplace_exists<V, 2, int &>(), "");
- static_assert(emplace_exists<V, 2, const int &>(), "");
- static_assert(emplace_exists<V, 2, int &&>(), "");
- static_assert(!emplace_exists<V, 2, void *>(),
- "not constructible from void*");
- static_assert(emplace_exists<V, 3, int>(), "");
- static_assert(!emplace_exists<V, 3, int &>(), "cannot bind ref");
- static_assert(!emplace_exists<V, 3, const int &>(), "cannot bind ref");
- static_assert(!emplace_exists<V, 3, const int &&>(), "cannot bind ref");
- static_assert(!emplace_exists<V, 4>(), "no ctors");
- }
-#endif
}
void test_basic() {
@@ -113,41 +90,6 @@ void test_basic() {
assert(std::get<4>(v) == "aaa");
assert(&ref3 == &std::get<4>(v));
}
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int, long, const int &, int &&, TestTypes::NoCtors,
- std::string>;
- const int x = 100;
- int y = 42;
- int z = 43;
- V v(std::in_place_index<0>, -1);
- // default emplace a value
- auto& ref1 = v.emplace<1>();
- static_assert(std::is_same_v<long&, decltype(ref1)>, "");
- assert(std::get<1>(v) == 0);
- assert(&ref1 == &std::get<1>(v));
- // emplace a reference
- auto& ref2 = v.emplace<2>(x);
- static_assert(std::is_same_v<&, decltype(ref)>, "");
- assert(&std::get<2>(v) == &x);
- assert(&ref2 == &std::get<2>(v));
- // emplace an rvalue reference
- auto& ref3 = v.emplace<3>(std::move(y));
- static_assert(std::is_same_v<&, decltype(ref)>, "");
- assert(&std::get<3>(v) == &y);
- assert(&ref3 == &std::get<3>(v));
- // re-emplace a new reference over the active member
- auto& ref4 = v.emplace<3>(std::move(z));
- static_assert(std::is_same_v<&, decltype(ref)>, "");
- assert(&std::get<3>(v) == &z);
- assert(&ref4 == &std::get<3>(v));
- // emplace with multiple args
- auto& ref5 = v.emplace<5>(3u, 'a');
- static_assert(std::is_same_v<std::string&, decltype(ref5)>, "");
- assert(std::get<5>(v) == "aaa");
- assert(&ref5 == &std::get<5>(v));
- }
-#endif
}
int main(int, char**) {
diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.mod/emplace_type_args.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.mod/emplace_type_args.pass.cpp
index 24305aa0a35dae..4e9f67775d10c4 100644
--- a/libcxx/test/std/utilities/variant/variant.variant/variant.mod/emplace_type_args.pass.cpp
+++ b/libcxx/test/std/utilities/variant/variant.variant/variant.mod/emplace_type_args.pass.cpp
@@ -54,30 +54,6 @@ void test_emplace_sfinae() {
static_assert(emplace_exists<V, const void *, int *>(), "");
static_assert(!emplace_exists<V, TestTypes::NoCtors>(), "cannot construct");
}
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- using V = std::variant<int, int &, const int &, int &&, long, long,
- TestTypes::NoCtors>;
- static_assert(emplace_exists<V, int>(), "");
- static_assert(emplace_exists<V, int, int>(), "");
- static_assert(emplace_exists<V, int, long long>(), "");
- static_assert(!emplace_exists<V, int, int, int>(), "too many args");
- static_assert(emplace_exists<V, int &, int &>(), "");
- static_assert(!emplace_exists<V, int &>(), "cannot default construct ref");
- static_assert(!emplace_exists<V, int &, const int &>(), "cannot bind ref");
- static_assert(!emplace_exists<V, int &, int &&>(), "cannot bind ref");
- static_assert(emplace_exists<V, const int &, int &>(), "");
- static_assert(emplace_exists<V, const int &, const int &>(), "");
- static_assert(emplace_exists<V, const int &, int &&>(), "");
- static_assert(!emplace_exists<V, const int &, void *>(),
- "not constructible from void*");
- static_assert(emplace_exists<V, int &&, int>(), "");
- static_assert(!emplace_exists<V, int &&, int &>(), "cannot bind ref");
- static_assert(!emplace_exists<V, int &&, const int &>(), "cannot bind ref");
- static_assert(!emplace_exists<V, int &&, const int &&>(), "cannot bind ref");
- static_assert(!emplace_exists<V, long, long>(), "ambiguous");
- static_assert(!emplace_exists<V, TestTypes::NoCtors>(),
- "cannot construct void");
-#endif
}
void test_basic() {
@@ -113,41 +89,6 @@ void test_basic() {
assert(std::get<4>(v) == "aaa");
assert(&ref3 == &std::get<4>(v));
}
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- {
- using V = std::variant<int, long, const int &, int &&, TestTypes::NoCtors,
- std::string>;
- const int x = 100;
- int y = 42;
- int z = 43;
- V v(std::in_place_index<0>, -1);
- // default emplace a value
- auto& ref1 = v.emplace<long>();
- static_assert(std::is_same_v<long&, decltype(ref1)>, "");
- assert(std::get<long>(v) == 0);
- assert(&ref1 == &std::get<long>(v));
- // emplace a reference
- auto& ref2 = v.emplace<const int &>(x);
- static_assert(std::is_same_v<const int&, decltype(ref2)>, "");
- assert(&std::get<const int &>(v) == &x);
- assert(&ref2 == &std::get<const int &>(v));
- // emplace an rvalue reference
- auto& ref3 = v.emplace<int &&>(std::move(y));
- static_assert(std::is_same_v<int &&, decltype(ref3)>, "");
- assert(&std::get<int &&>(v) == &y);
- assert(&ref3 == &std::get<int &&>(v));
- // re-emplace a new reference over the active member
- auto& ref4 = v.emplace<int &&>(std::move(z));
- static_assert(std::is_same_v<int &, decltype(ref4)>, "");
- assert(&std::get<int &&>(v) == &z);
- assert(&ref4 == &std::get<int &&>(v));
- // emplace with multiple args
- auto& ref5 = v.emplace<std::string>(3u, 'a');
- static_assert(std::is_same_v<std::string&, decltype(ref5)>, "");
- assert(std::get<std::string>(v) == "aaa");
- assert(&ref5 == &std::get<std::string>(v));
- }
-#endif
}
int main(int, char**) {
diff --git a/libcxx/test/std/utilities/variant/variant.visit.member/visit.pass.cpp b/libcxx/test/std/utilities/variant/variant.visit.member/visit.pass.cpp
index 68706d6c32af4f..2ee7d4cfbb114d 100644
--- a/libcxx/test/std/utilities/variant/variant.visit.member/visit.pass.cpp
+++ b/libcxx/test/std/utilities/variant/variant.visit.member/visit.pass.cpp
@@ -81,39 +81,6 @@ void test_argument_forwarding() {
std::move(cv).visit(obj);
assert(Fn::check_call<const int&&>(val));
}
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- { // single argument - lvalue reference
- using V = std::variant<int&>;
- int x = 42;
- V v(x);
- const V& cv = v;
-
- v.visit(obj);
- assert(Fn::check_call<int&>(val));
- cv.visit(obj);
- assert(Fn::check_call<int&>(val));
- std::move(v).visit(obj);
- assert(Fn::check_call<int&>(val));
- std::move(cv).visit(obj);
- assert(Fn::check_call<int&>(val));
- assert(false);
- }
- { // single argument - rvalue reference
- using V = std::variant<int&&>;
- int x = 42;
- V v(std::move(x));
- const V& cv = v;
-
- v.visit(obj);
- assert(Fn::check_call<int&>(val));
- cvstd::visit(obj);
- assert(Fn::check_call<int&>(val));
- std::move(v).visit(obj);
- assert(Fn::check_call<int&&>(val));
- std::move(cv).visit(obj);
- assert(Fn::check_call<int&&>(val));
- }
-#endif
}
void test_return_type() {
diff --git a/libcxx/test/std/utilities/variant/variant.visit.member/visit_return_type.pass.cpp b/libcxx/test/std/utilities/variant/variant.visit.member/visit_return_type.pass.cpp
index 20472c62fc5f98..b12c25761a9357 100644
--- a/libcxx/test/std/utilities/variant/variant.visit.member/visit_return_type.pass.cpp
+++ b/libcxx/test/std/utilities/variant/variant.visit.member/visit_return_type.pass.cpp
@@ -109,38 +109,6 @@ void test_argument_forwarding() {
std::move(cv).visit<ReturnType>(obj);
assert(Fn::check_call<const int&&>(val));
}
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- { // single argument - lvalue reference
- using V = std::variant<int&>;
- int x = 42;
- V v(x);
- const V& cv = v;
-
- v.visit<ReturnType>(obj);
- assert(Fn::check_call<int&>(val));
- cv.visit<ReturnType>(obj);
- assert(Fn::check_call<int&>(val));
- std::move(v).visit<ReturnType>(obj);
- assert(Fn::check_call<int&>(val));
- std::move(cv).visit<ReturnType>(obj);
- assert(Fn::check_call<int&>(val));
- }
- { // single argument - rvalue reference
- using V = std::variant<int&&>;
- int x = 42;
- V v(std::move(x));
- const V& cv = v;
-
- v.visit<ReturnType>(obj);
- assert(Fn::check_call<int&>(val));
- cv.visit<ReturnType>(obj);
- assert(Fn::check_call<int&>(val));
- std::move(v).visit<ReturnType>(obj);
- assert(Fn::check_call<int&&>(val));
- std::move(cv).visit<ReturnType>(obj);
- assert(Fn::check_call<int&&>(val));
- }
-#endif
}
template <typename ReturnType>
diff --git a/libcxx/test/std/utilities/variant/variant.visit/visit.pass.cpp b/libcxx/test/std/utilities/variant/variant.visit/visit.pass.cpp
index 097b784f2bf2ce..43bc35ff80d40a 100644
--- a/libcxx/test/std/utilities/variant/variant.visit/visit.pass.cpp
+++ b/libcxx/test/std/utilities/variant/variant.visit/visit.pass.cpp
@@ -117,36 +117,6 @@ void test_argument_forwarding() {
std::visit(obj, std::move(cv));
assert(Fn::check_call<const int &&>(Val));
}
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- { // single argument - lvalue reference
- using V = std::variant<int &>;
- int x = 42;
- V v(x);
- const V &cv = v;
- std::visit(obj, v);
- assert(Fn::check_call<int &>(Val));
- std::visit(obj, cv);
- assert(Fn::check_call<int &>(Val));
- std::visit(obj, std::move(v));
- assert(Fn::check_call<int &>(Val));
- std::visit(obj, std::move(cv));
- assert(Fn::check_call<int &>(Val));
- }
- { // single argument - rvalue reference
- using V = std::variant<int &&>;
- int x = 42;
- V v(std::move(x));
- const V &cv = v;
- std::visit(obj, v);
- assert(Fn::check_call<int &>(Val));
- std::visit(obj, cv);
- assert(Fn::check_call<int &>(Val));
- std::visit(obj, std::move(v));
- assert(Fn::check_call<int &&>(Val));
- std::visit(obj, std::move(cv));
- assert(Fn::check_call<int &&>(Val));
- }
-#endif
{ // multi argument - multi variant
using V = std::variant<int, std::string, long>;
V v1(42), v2("hello"), v3(43l);
diff --git a/libcxx/test/std/utilities/variant/variant.visit/visit_return_type.pass.cpp b/libcxx/test/std/utilities/variant/variant.visit/visit_return_type.pass.cpp
index eb425c07f93222..5c20d69bbe93e9 100644
--- a/libcxx/test/std/utilities/variant/variant.visit/visit_return_type.pass.cpp
+++ b/libcxx/test/std/utilities/variant/variant.visit/visit_return_type.pass.cpp
@@ -119,36 +119,6 @@ void test_argument_forwarding() {
std::visit<ReturnType>(obj, std::move(cv));
assert(Fn::check_call<const int &&>(Val));
}
-#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
- { // single argument - lvalue reference
- using V = std::variant<int &>;
- int x = 42;
- V v(x);
- const V &cv = v;
- std::visit<ReturnType>(obj, v);
- assert(Fn::check_call<int &>(Val));
- std::visit<ReturnType>(obj, cv);
- assert(Fn::check_call<int &>(Val));
- std::visit<ReturnType>(obj, std::move(v));
- assert(Fn::check_call<int &>(Val));
- std::visit<ReturnType>(obj, std::move(cv));
- assert(Fn::check_call<int &>(Val));
- }
- { // single argument - rvalue reference
- using V = std::variant<int &&>;
- int x = 42;
- V v(std::move(x));
- const V &cv = v;
- std::visit<ReturnType>(obj, v);
- assert(Fn::check_call<int &>(Val));
- std::visit<ReturnType>(obj, cv);
- assert(Fn::check_call<int &>(Val));
- std::visit<ReturnType>(obj, std::move(v));
- assert(Fn::check_call<int &&>(Val));
- std::visit<ReturnType>(obj, std::move(cv));
- assert(Fn::check_call<int &&>(Val));
- }
-#endif
{ // multi argument - multi variant
using V = std::variant<int, std::string, long>;
V v1(42), v2("hello"), v3(43l);
diff --git a/libcxx/test/support/variant_test_helpers.h b/libcxx/test/support/variant_test_helpers.h
index c174cba3284019..dd941e654ab787 100644
--- a/libcxx/test/support/variant_test_helpers.h
+++ b/libcxx/test/support/variant_test_helpers.h
@@ -21,9 +21,6 @@
#error This file requires C++17
#endif
-// FIXME: Currently the variant<T&> tests are disabled using this macro.
-#define TEST_VARIANT_HAS_NO_REFERENCES
-
// TODO(LLVM-19): Remove TEST_VARIANT_ALLOWS_NARROWING_CONVERSIONS
#ifdef _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT
# define TEST_VARIANT_ALLOWS_NARROWING_CONVERSIONS
>From c71a90483ea3aabd69170926a406a4d756fe1d34 Mon Sep 17 00:00:00 2001
From: Hui <hui.xie0621 at gmail.com>
Date: Thu, 7 Mar 2024 08:41:02 +0000
Subject: [PATCH 2/2] [libc++][test] remove tests that testing std::variant<T&>
---
.../test/std/utilities/variant/variant.get/get_if_index.pass.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/libcxx/test/std/utilities/variant/variant.get/get_if_index.pass.cpp b/libcxx/test/std/utilities/variant/variant.get/get_if_index.pass.cpp
index 6b923905b7530f..09e2e85abe6681 100644
--- a/libcxx/test/std/utilities/variant/variant.get/get_if_index.pass.cpp
+++ b/libcxx/test/std/utilities/variant/variant.get/get_if_index.pass.cpp
@@ -67,7 +67,6 @@ void test_get_if() {
assert(*std::get_if<1>(&v) == 42);
assert(std::get_if<0>(&v) == nullptr);
}
-// FIXME: Remove these once reference support is reinstated
}
int main(int, char**) {
More information about the libcxx-commits
mailing list