| 1 |
// PR c++/79620 |
| 2 |
// [expr.prim.id.unqual] example 1 |
| 3 |
// { dg-do compile { target c++11 } } |
| 4 |
|
| 5 |
void f() { |
| 6 |
float x, &r = x; |
| 7 |
|
| 8 |
[=]() -> decltype((x)) { // lambda returns float const& because this lambda is not mutable and |
| 9 |
// x is an lvalue |
| 10 |
decltype(x) y1; // y1 has type float |
| 11 |
decltype((x)) y2 = y1; // y2 has type float const& |
| 12 |
decltype(r) r1 = y1; // r1 has type float& |
| 13 |
decltype((r)) r2 = y2; // r2 has type float const& |
| 14 |
return y2; // { dg-bogus "'float&' to 'const float'" "" { xfail *-*-* } } |
| 15 |
}; |
| 16 |
|
| 17 |
[=](decltype((x)) y) { |
| 18 |
decltype((x)) z = x; // OK, y has type float&, z has type float const& |
| 19 |
}; |
| 20 |
|
| 21 |
[=] { |
| 22 |
[](decltype((x)) y) {}; // OK, lambda takes a parameter of type float const& |
| 23 |
|
| 24 |
#if __cpp_init_captures |
| 25 |
[x=1](decltype((x)) y) { |
| 26 |
decltype((x)) z = x; // OK, y has type int&, z has type int const& |
| 27 |
}; |
| 28 |
#endif |
| 29 |
}; |
| 30 |
} |