Hacker News new | ask | show | jobs
by GuB-42 1118 days ago
Some functions are pointless without their return value, not using the return value is most likely a bug, and it is good to have a warning. If using the function without using the return value is not a bug, then there is a problem with your codebase.
1 comments

std::clamp ; I got it exactly wrong and would have introduced a bug if the compiled didn't tell me I was discarding the return value. I thought it updated the value I wanted clamped. It does not. Don't know why I thought that, but I did.

The function is entirely useless and pointless to call without using the returned value, and [[nodiscard]] pointed this out to me. Perfect.