Search code examples
c++templateslambdac++14auto

Lambda in lambda cannot be a template?


The Visual Studio compiler (MSVC 2015) is unable to compile the following simple piece of code:

int main() {
    auto foo = [](auto callback) {
        callback(int{});
    };
    auto rexs = [&foo]() {
        foo([](auto tg) {});
    };
}

It barfs an internal compiler error:

fatal error C1001: An internal error has occurred in the compiler.

VC++ likes to give error C1001 when the compiled code contains errors (i.e. the programmer made a mistake, but VC++ just doesn't fully recognize the mistake in the code), so I'm wondering if I could have made a mistake here.

However, from all perspectives I can see, my code looks standard-conformant, and it seems like a VC++ bug to me. Am I thinking right?


Solution

  • Your code compiles fine with clang 3.8 and gcc 5.4 (http://rextester.com/SCAH69935) so it seems to be a VC++ bug.