[[nodiscard]] and KDE coding policy
Ingo Klöcker
kloecker at kde.org
Thu Jul 30 17:00:59 BST 2026
On Donnerstag, 30. Juli 2026 17:14:44 Mitteleuropäische Sommerzeit David
Edmundson wrote:
> I'm seeing more and more merge requests using [[nodiscard]] and now
> review comments insisting on others adding [[nodiscard]] to new code.
>
> I've seen everyone has their own set of rules:
> - some don't use it
> - some add it when the return value is important (like opening a file
> having an error)
> or when the return value has a RAII pattern or requires the caller to
> take over memory ownership
> - some add it to every getter
>
> I don't like inconsistency and I don't like repeated discussions on
> merge requests.
>
> I would like to as a group decide on something and add it to
> https://community.kde.org/Policies/Library_Code_Policy at least for
> new code with a definitive rule that everyone has to follow.
>
> Whether we change existing code is also up for discussion it's a
> source-incompatible change even though it's binary compatible.
Is it a source-incompatible change (as in it breaks the build of using code)?
The compiler will throw warnings like in
https://invent.kde.org/pim/kmbox/-/jobs/4766098, but unless you tell the
compiler to fail on these warnings it seems to be source compatible.
I'd prefer [[nodiscard]] to be used only if the return value really shouldn't
be ignored.
This is Qt's [[nodiscard]] policy:
https://contribute.qt-project.org/quips/19
Regards,
Ingo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 265 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-devel/attachments/20260730/c279842b/attachment.sig>
More information about the kde-devel
mailing list