2

Consider the following example:

#include <functional>

int main() { 
    const int x = 42;
    auto fn = [&x = x]() { return x; };
    fn();
}

It compiles fine with clang 3.6.2, while it does not compile with GCC 5.3.1.
On the other side, the following code fails to compile with both of them:

#include <functional>

int main() { 
    const int x = 42;
    auto fn = [&x = x]() { x = 1; };
    fn();
}

Which compiler is right for the first example?

skypjack
  • 47,379
  • 17
  • 84
  • 173

0 Answers0