1 // { dg-do run { target c++11 } } 2 // { dg-options "" } 3 4 struct A { int i; long long j; } a[64]; 5 A b[32]; 6 7 template <typename T> 8 void foo(T & b)9foo (T &b) 10 { 11 int i = 0; 12 for (auto &x : a) 13 { 14 x.i = i; 15 x.j = 2 * i++; 16 } 17 for (auto & [ x, y ] : a) // { dg-warning "structured bindings only available with" "" { target c++14_down } } 18 { 19 x += 2; 20 y += 3; 21 } 22 i = 0; 23 for (const auto [ u, v ] : a) // { dg-warning "structured bindings only available with" "" { target c++14_down } } 24 { 25 if (u != i + 2 || v != 2 * i++ + 3) 26 __builtin_abort (); 27 } 28 i = 0; 29 for (auto [ x, y ] : a) // { dg-warning "structured bindings only available with" "" { target c++14_down } } 30 { 31 x += 4; 32 y += 5; 33 if (x != i + 6 || y != 2 * i++ + 8) 34 __builtin_abort (); 35 } 36 i = 0; 37 for (const auto x : a) 38 { 39 if (x.i != i + 2 || x.j != 2 * i++ + 3) 40 __builtin_abort (); 41 } 42 i = 0; 43 for (auto &x : b) 44 { 45 x.i = i; 46 x.j = 2 * i++; 47 } 48 for (auto & [ x, y ] : b) // { dg-warning "structured bindings only available with" "" { target c++14_down } } 49 { 50 x -= 2; 51 y -= 3; 52 } 53 i = 0; 54 for (const auto [ u, v ] : b) // { dg-warning "structured bindings only available with" "" { target c++14_down } } 55 { 56 if (u != i - 2 || v != 2 * i++ - 3) 57 __builtin_abort (); 58 } 59 i = 0; 60 for (auto [ x, y ] : b) // { dg-warning "structured bindings only available with" "" { target c++14_down } } 61 { 62 x -= 4; 63 y -= 5; 64 if (x != i - 6 || y != 2 * i++ - 8) 65 __builtin_abort (); 66 } 67 i = 0; 68 for (const auto x : b) 69 { 70 if (x.i != i - 2 || x.j != 2 * i++ - 3) 71 __builtin_abort (); 72 } 73 } 74 75 int main()76main () 77 { 78 foo (b); 79 for (int i = 0; i < 64; i++) 80 { 81 if (a[i].i != i + 2 || a[i].j != 2 * i + 3) 82 __builtin_abort (); 83 if (i >= 32) 84 continue; 85 if (b[i].i != i - 2 || b[i].j != 2 * i - 3) 86 __builtin_abort (); 87 } 88 } 89