4 ms·
It'll throw an error for myFunc(); but not for auto foo = myFunc(); if myFunc returns a mustUse type.
by Doxin 4y ago
It'll throw an error for
myFunc();
but not for
auto foo = myFunc();
if myFunc returns a mustUse type.
- giancarlostoro 4y agoThank you, I know it looks stupid simple but code helps me put it into a perspective I can remember better vs only reading documentation about code. That is kind of an interesting way to sort of force someone to not just throw away a return value. Question: Do you know if this would also be fine if the called function was in a return statement?
- Doxin 4y agoThis will only cause an error if both of these are true: - if the expression is the top level expression in a statement (like in my example code) or the left hand side in a comma expression - if the expression is not an assignment, increment, or decrement So using it in a return is fine because then the expression is no longer the top level in the statement, the return is. Of course then the function calling THAT function must deal with not discarding the value. It's pretty neat.