As far as I know, in standard C++11 (not C++14), when omitting the return type of a lambda, its return type is deduced to be:
- The type of the returned expression, whenever the lambda consists of only one
returnstatement, or voidin all other cases.
Consider now this code:
#include <iostream>
auto closure = [](int x)
{
x++;
return x;
};
int main()
{
int y = closure(10);
std::cout << y << std::endl;
}
This should fall under case 2., however the code compiles as if were C++14 with auto type deduction, in both g++4.9.2, g++5 and clang++, with -pedantic -Wall -Wextra -std=c++11. What's going on here? Am I interpreting the standard wrong?
Aucun commentaire:
Enregistrer un commentaire