[1] https://en.wikipedia.org/wiki/Substructural_type_system#Diff...
myFunc();
but not for auto foo = myFunc();
if myFunc returns a mustUse type.Question: Do you know if this would also be fine if the called function was in a return statement?
- 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.
https://en.cppreference.com/w/cpp/language/attributes/nodisc...
https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attribute...
I can fix it but the example given is clear, no?
Working on updating that.
I think the reason the documentation is cryptic is because it's a library-supplied User Data Attribute that is specially recognized by the compiler. The documentation generator is having trouble with it. In code it's pretty simple:
https://github.com/dlang/druntime/blob/705fb36e5fc4d930eed85...
e.g. if you return something that could contain an error then ignoring the return value could be disastrous.