This is rejected by g++ (4.9.3 and 5.2.0), but is accepted by clang 3.5.0:
int main() {
const int ci = 0;
auto lambda = [ &cap = ci ]() { };
}
g++ gives error: binding ‘const int’ to reference of type ‘int&’ discards qualifiers
. It appears that g++ refuses to allow non-const references to be captured, except of course using plain old C++11 capture [&ci]
. That seems a very strange constraint, perhaps a bug in g++?