Cannot declare lambda with auto in VS 14 CTP: conditional expression like 'void' is illegal

using Visual Studio 2014 CTP, C ++ (v140) compiler:

auto gp = [&](BYTE* buff) {
     auto gp1 = [](char* bff, char** p1) {
                *p1 = strstr((char*)bff, "(");
                return (*p1);
     };
};

Error:

conditional expression of type 'void' is illegal

(maybe autothere is really a wrong type in there?)

If I declare the inner lambda as std::function<char*(char*, char**)> gp1, then it works

Is there something I'm doing wrong or is this a compiler error?

+4
source share
1 answer

I am not starting 2014, but you may need to specify the internal return type of lambda (which may be the default for void) using '-> char *' as follows:

auto gp = [&](BYTE* buff) {
    auto gp1 = [](char* bff, char** p1) -> char* {
        *p1 = strstr((char*)bff, "(");
        return (*p1);
    };
};
0
source

Source: https://habr.com/ru/post/1543343/


All Articles