aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/std/ranges/subrange/lwg3589.cc
blob: 1ccc52d81f8a032a12f156e072d916063be90ed9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// { dg-do compile { target c++20 } }

// LWG 3589. The const lvalue reference overload of get for subrange does not
// constrain I to be copyable when N == 0

#include <ranges>
#include <testsuite_iterators.h>

void
test_lwg3589()
{
  int a[2]{};
  __gnu_test::test_range<int, __gnu_test::input_iterator_wrapper_nocopy> r(a);

  // Use a generic lambda so we have a dependent context.
  auto test = [](auto& x)
    {
      // This was wrong before the LWG 3589 change:
      if constexpr (requires { std::ranges::get<0>(x); })
	(void) std::ranges::get<0>(x);

      // These always worked unconditionally:
      (void) std::ranges::get<1>(x);
      (void) std::ranges::get<0>(std::move(x));
      (void) std::ranges::get<1>(std::move(x));
    };

  std::ranges::subrange sr(r.begin(), r.end());
  test(sr);
}