| 1 |
// Test for decltype of direct decomposition. |
| 2 |
// { dg-do compile { target c++17 } } |
| 3 |
|
| 4 |
template <class,class> struct same_type; |
| 5 |
template <class T> struct same_type<T,T> {}; |
| 6 |
|
| 7 |
struct A { |
| 8 |
int i; |
| 9 |
const int ci = 42; |
| 10 |
mutable int mi; |
| 11 |
int& r = i; |
| 12 |
const int& cr = ci; |
| 13 |
} a; |
| 14 |
|
| 15 |
void f() { |
| 16 |
auto [i,ci,mi,r,cr] = a; |
| 17 |
|
| 18 |
same_type<decltype(i),int>{}; |
| 19 |
same_type<decltype(ci),const int>{}; |
| 20 |
same_type<decltype(mi),int>{}; |
| 21 |
same_type<decltype(r),int&>{}; |
| 22 |
same_type<decltype(cr),const int&>{}; |
| 23 |
} |
| 24 |
void frr() { |
| 25 |
auto &&[i,ci,mi,r,cr] = a; |
| 26 |
|
| 27 |
same_type<decltype(i),int>{}; |
| 28 |
same_type<decltype(ci),const int>{}; |
| 29 |
same_type<decltype(mi),int>{}; |
| 30 |
same_type<decltype(r),int&>{}; |
| 31 |
same_type<decltype(cr),const int&>{}; |
| 32 |
} |
| 33 |
void fc() { |
| 34 |
const auto [i,ci,mi,r,cr] = a; |
| 35 |
|
| 36 |
same_type<decltype(i),const int>{}; |
| 37 |
same_type<decltype(ci),const int>{}; |
| 38 |
same_type<decltype(mi),int>{}; |
| 39 |
same_type<decltype(r),int&>{}; |
| 40 |
same_type<decltype(cr),const int&>{}; |
| 41 |
} |
| 42 |
void frc() { |
| 43 |
const A ca{}; |
| 44 |
auto &[i,ci,mi,r,cr] = ca; |
| 45 |
|
| 46 |
same_type<decltype(i),const int>{}; |
| 47 |
same_type<decltype(ci),const int>{}; |
| 48 |
same_type<decltype(mi),int>{}; |
| 49 |
same_type<decltype(r),int&>{}; |
| 50 |
same_type<decltype(cr),const int&>{}; |
| 51 |
} |