#include <type_traits>
int x = 0;
void f(int const x)
{
static_assert(std::is_const_v<decltype(x)>); // ok
}
int main()
{
int n = 0;
[n, m = n]
{
static_assert(std::is_const_v<decltype(m)>); // ok
static_assert(std::is_const_v<decltype(n)>); // err
};
}
See online demo
Why does decltype(captured_var) not behave as expected?