| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
|
| 3 |
// LWG 3589. The const lvalue reference overload of get for subrange does not |
| 4 |
// constrain I to be copyable when N == 0 |
| 5 |
|
| 6 |
#include <ranges> |
| 7 |
#include <testsuite_iterators.h> |
| 8 |
|
| 9 |
void |
| 10 |
test_lwg3589() |
| 11 |
{ |
| 12 |
int a[2]{}; |
| 13 |
__gnu_test::test_range<int, __gnu_test::input_iterator_wrapper_nocopy> r(a); |
| 14 |
|
| 15 |
// Use a generic lambda so we have a dependent context. |
| 16 |
auto test = [](auto& x) |
| 17 |
{ |
| 18 |
// This was wrong before the LWG 3589 change: |
| 19 |
if constexpr (requires { std::ranges::get<0>(x); }) |
| 20 |
(void) std::ranges::get<0>(x); |
| 21 |
|
| 22 |
// These always worked unconditionally: |
| 23 |
(void) std::ranges::get<1>(x); |
| 24 |
(void) std::ranges::get<0>(std::move(x)); |
| 25 |
(void) std::ranges::get<1>(std::move(x)); |
| 26 |
}; |
| 27 |
|
| 28 |
std::ranges::subrange sr(r.begin(), r.end()); |
| 29 |
test(sr); |
| 30 |
} |