I have been attempting to understand when and when not a lambda with a capture-default odr-uses a variable with automatic storage duration defined in its surrounding scope (prompted by this answer). While exploring around this I came across a little curiosity. GCC and Clang appear to disagree about the value category of the id-expression n 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 compiles the code successfully, while GCC does not (error: use of deleted function). Which one is correct? Or is this something that is unspecified or implementation-defined?
Binding a reference to an object is supposed to odr-use it, and this is confirmed by removing the lambda's capture-default and observing that both compilers then complain that n can not be implicitly captured without a capture-default.
Marking the lambda as mutable makes no appreciable difference to the compilers' output.
nnot being captured if we remove the capture-default. Seems to just be an obvious bug.nas a constant expression, which it may be allowed to do.