| 1 |
// P0963R3 - Structured binding declaration as a condition |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
// { dg-options "" } |
| 4 |
|
| 5 |
namespace std { |
| 6 |
template<typename T> struct tuple_size; |
| 7 |
template<int, typename> struct tuple_element; |
| 8 |
} |
| 9 |
|
| 10 |
struct S { |
| 11 |
S () : s (0) {} |
| 12 |
S (int x) : s (x) {} |
| 13 |
S (const S &x) : s (x.s) {} |
| 14 |
~S () {} |
| 15 |
int s; |
| 16 |
}; |
| 17 |
|
| 18 |
struct T { |
| 19 |
S a, b, c; |
| 20 |
~T () {} |
| 21 |
explicit operator bool () const noexcept { return a.s == b.s; } |
| 22 |
template <int I> S get () { return I ? a : b; } |
| 23 |
}; |
| 24 |
|
| 25 |
template<> struct std::tuple_size<T> { static const int value = 2; }; |
| 26 |
template<int I> struct std::tuple_element<I,T> { using type = S; }; |
| 27 |
|
| 28 |
void |
| 29 |
foo (T t, bool x) |
| 30 |
{ |
| 31 |
while (auto [ i, j ] = T { 1, 1, 3 }) // { dg-warning "structured bindings in conditions only available with" "" { target c++23_down } } |
| 32 |
{ |
| 33 |
if (x) |
| 34 |
break; |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
void |
| 39 |
bar (T t, bool x) |
| 40 |
{ |
| 41 |
for (int cnt = 0; auto [ i, j ] = T { 2, 2, 4 }; ++cnt) // { dg-warning "structured bindings in conditions only available with" "" { target c++23_down } } |
| 42 |
{ |
| 43 |
if (x) |
| 44 |
break; |
| 45 |
} |
| 46 |
} |