Re: [[nodiscard]] and KDE coding policy

Ingo Klöcker <[email protected]> Thu, 30 Jul 2026 18:00:59 +0200
Newsgroups gmane.comp.kde.devel.general
Message-ID <[email protected]>
--nextPartVm8EhvXLQg68Vp3oviXRzA
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="utf-8"; protected-headers="v1"
From: Ingo =?UTF-8?B?S2zDtmNrZXI=?= <[email protected]>
To: [email protected]
Subject: Re: [[nodiscard]] and KDE coding policy
Date: Thu, 30 Jul 2026 18:00:59 +0200
Message-ID: <[email protected]>
In-Reply-To:  <CAGeFrHB4Ovudh1Tf-D6q=tar3E-h7f_2tu_9Q+JeoHb3qJZC9w@mail.gmail.com>
References:  <CAGeFrHB4Ovudh1Tf-D6q=tar3E-h7f_2tu_9Q+JeoHb3qJZC9w@mail.gmail.com>
MIME-Version: 1.0

On Donnerstag, 30. Juli 2026 17:14:44 Mitteleurop=C3=A4ische Sommerzeit Dav=
id=20
Edmundson wrote:
> I'm seeing more and more merge requests using [[nodiscard]] and now
> review comments insisting on others adding [[nodiscard]] to new code.
>=20
> 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
>=20
> I don't like inconsistency and I don't like repeated discussions on
> merge requests.
>=20
> 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.
>=20
> 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=
)?=20
The compiler will throw warnings like in
https://invent.kde.org/pim/kmbox/-/jobs/4766098, but unless you tell the=20
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=20
be ignored.

This is Qt's [[nodiscard]] policy:
https://contribute.qt-project.org/quips/19

Regards,
Ingo
--nextPartVm8EhvXLQg68Vp3oviXRzA
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part.
Content-Transfer-Encoding: 7Bit

-----BEGIN PGP SIGNATURE-----

iJEEABYKADkWIQTbjgIOMowwlCBgvyGxb1mVFkdKugUCamt1OxsUgAAAAAAEAA5t
YW51MiwyLjUrMS4xMiwyLDIACgkQsW9ZlRZHSrrLawEAhG27ALiBCsg+uTVE1jsg
y8V8fExd01gGl/nnNw1jwvQA/RXt+f6KVx3ClT3YvS/kRvM/Bd6a5Qo33gss0CYw
mw0I
=P1n5
-----END PGP SIGNATURE-----

--nextPartVm8EhvXLQg68Vp3oviXRzA--