[[nodiscard]] and KDE coding policy
Jin Liu
m.liu.jin at gmail.com
Fri Jul 31 01:53:31 BST 2026
Vlad Zahorodnii <vlad.zahorodnii at kde.org> 于2026年7月31日周五 04:22写道:
> That being said, I still don't think that adding [[nodiscard]] to
> functions such as getters is a good idea. It makes code more verbose,
> with more boilerplate, with little (imho) benefit. Stray getter calls
> are odd but the effort to avoid them is hard to justify.
Yeah, I don't think getters need `[[nodiscard]]`, for the same reason that
`std::min` and `std::move` don't have it:
1. It's very unlikely that one would ignore the return value.
2. Even when mistakenly ignored, there's no effect.
So maybe we could restrict the use to:
A) Pure functions that (due to unfortunate naming) might be mistakenly
assumed to be mutating. E.g., `container.empty()`.
B) Mutating functions that might be mistakenly assumed to have no
return value. And the return value really needs to be checked.
I think this is similar to the Qt rule quoted earlier (except its
"MAY" clause 2).
-Jin
More information about the kde-devel
mailing list