Skip to content

Commit

Permalink
[libc++][test] Remove tests that testing std::variant<T&> (#84222)
Browse files Browse the repository at this point in the history
Fixes #83600
  • Loading branch information
huixie90 authored Mar 26, 2024
1 parent 308ed02 commit dfde6e8
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 695 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -91,37 +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
#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**) {
Expand Down
55 changes: 0 additions & 55 deletions libcxx/test/std/utilities/variant/variant.get/get_if_type.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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**) {
Expand Down
121 changes: 0 additions & 121 deletions libcxx/test/std/utilities/variant/variant.get/get_index.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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>;
Expand Down
Loading

0 comments on commit dfde6e8

Please sign in to comment.