Value class of const int captured by lambda

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.

+8
c ++ language-lawyer lambda c ++ 17 value-categories
source share

No one has answered this question yet.

See similar questions:

61
Why is the const variable sometimes not needed for capture in lambda?
7
Why is this nested lambda not considered constexpr?

or similar:

1239
What is the difference between const int *, const int * const and int const *?
33
Calling the `this` member function from a common lambda-clang vs gcc
sixteen
Empty lambda expression
14
How to use constexpr value in lambda?
thirteen
Capturing static lambda in nested lambda
10
decltype () of the captured variable in lambda: GCC error and / or Clang error?
nine
The copied const object in lambda closure is not changed
6
Dependent expression and ODR usage in common Lambda in C ++ 14
6
how can this lambda with an empty capture list refer to the scope name?
2
Lambda immutable function: copied captured variables allowed as const?

All Articles