Consider the following code:
#include <type_traits>
int main()
{
auto l = [k = 0]
{
static_assert(std::is_same_v<decltype(k), int>);
};
}
clang++
(10.x and trunk) happily compiles the code above.g++
(10.x and trunk) fails to compile the code above with the following error:error: static assertion failed 10 | static_assert(std::is_same_v<decltype(k), int>); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Apparently,
g++
believes thatdecltype(k)
evaluates toconst int
.
Since the type of the data member k
should be deduced from 0
(which is a plain, non-const
, int
), I think that this is a g++
bug. In my mental model, the only thing that is const
is the operator()
of the lambda, but not the synthesized data member k
.
Is my assessment correct?
What does the standard say?