In ISO C++ N4849, [expr.prim.id.unqual] paragraph 2, there is an example:
void f() {
float x, &r = x;
[=] {
decltype(x) y1; // y1 has type float
decltype((x)) y2 = y1; // y2 has type float
//const& because this lambda
// is not mutable and x is an lvalue
decltype(r) r1 = y1; // r1 has type float&
decltype((r)) r2 = y2; // r2 has type float const&
};
}
But it fails to compile in GCC 8.1.0 -std = c++2a
Is it a bug? Or other reasons? The type deduced in decltype((r))
is not expected. It's deduced to float&
instead.
c:\Cpptest\source.cpp: In lambda function:
c:\Cpptest\source.cpp:8:24: error: binding reference of type 'float&' to 'const float' discards qualifiers
decltype((r)) r2 = y2; // r2 has type float const&