S
Scott Meyers
Both C++98/03 and draft C++0x say this:
Does anybody know why this is undefined behavior instead of a hard error?
It has an interesting implication for lambda expressions. Lambdas declaring a
return type but returning nothing yield UB and, with the compilers I tested,
don't necessarily issue a warning:
auto f = []()->int { std::cout << "Oops, I forgot to return something"; };
All enlightenment appreciated.
Scott
Flowing off the end of a function is equivalent to a return with no value; this results in undefined
behavior in a value-returning function.
Does anybody know why this is undefined behavior instead of a hard error?
It has an interesting implication for lambda expressions. Lambdas declaring a
return type but returning nothing yield UB and, with the compilers I tested,
don't necessarily issue a warning:
auto f = []()->int { std::cout << "Oops, I forgot to return something"; };
All enlightenment appreciated.
Scott