Re: [[nodiscard]] and KDE coding policy

Jin Liu <[email protected]> Fri, 31 Jul 2026 08:53:31 +0800
Newsgroups gmane.comp.kde.devel.general
Message-ID <CAHBr4f-60_WnKVFAEvBkVvkizVDxRJhycOZCegUUSD-sT+kWnQ@mail.gmail.com>
Vlad Zahorodnii <[email protected]> =E4=BA=8E2026=E5=B9=B47=E6=9C=883=
1=E6=97=A5=E5=91=A8=E4=BA=94 04:22=E5=86=99=E9=81=93=EF=BC=9A
> 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