3 ms·
@mustUse is a user defined attribute the compiler recognizes that forces return values it affects to be used. e.g. if you return something that could contain a
by mhh__ 4y ago
@mustUse is a user defined attribute the compiler recognizes that forces return values it affects to be used.
e.g. if you return something that could contain an error then ignoring the return value could be disastrous.
- loeg 4y agoA similar concept is used widely in glibc under the name “__wur” (shorthand for __attribute__((warn_unused_result))). https://github.com/bminor/glibc/search?q=__wur&type= https://github.com/bminor/glibc/search?q=__wur&type=
- Georgelemental 4y agoRust also has something similar, in the form of the `#[must_use]` attribute.
- loeg 4y agoYeah, and one called `[[nodiscard]]` in C++17 as well.
- giancarlostoro 4y agoI kind of get this much, but it would be nice to see a small set of code showcasing this in practice to really cement it in for me.