I am trying to understand when and when not a lambda with a fixed value-odr-uses a variable with automatic storage duration defined in its environment (caused by this answer ). Studying around this, I came across a little curiosity. GCC and Clang apparently disagree with the category of id id values ββin the following code:
template <typename T> void assert_is_lvalue(const T&) {} template <typename T> void assert_is_lvalue(const T&&) = delete; int main() { const int n = 0; [=] { assert_is_lvalue(n); }; }
Clang successfully compiles the code, but GCC does not ( error: use of deleted function ). Which one is correct? Or is it something that is not defined or defined by the implementation?
An object reference binding should use odr-use, and this is confirmed by removing the default lambda capture and observing that both compilers then complain that n cannot be implicitly captured without a default binding.
Marking the lambda as mutable does not make any noticeable difference in the output of the compilers.
c ++ language-lawyer lambda c ++ 17 value-categories
Oktalist
source share