[libcxx-dev] Proposal to replace `_LIBCPP_NODISCARD_EXT` with `[[nodiscard]]`

Christopher Di Bella via libcxx-dev libcxx-dev at lists.llvm.org
Thu May 13 10:47:11 PDT 2021


Hi folks,

There's been a lot of requests for `[[nodiscard]]` to be replaced with `
_LIBCPP_NODISCARD_EXT` in recent reviews where the standard doesn't
explicitly declare an entity with the nodiscard attribute. After some
investigation, I've discovered that this feature is confusing and
error-prone. `_LIBCPP_NODISCARD_EXT` is opt-in, which requires users to
know about its existence (I certainly didn't until reviewers started asking
for it, and even then, didn't expect it to be opt-in), and then has three
ways to opt out of its use: `_LIBCPP_DISABLE_NODISCARD_EXT` (global), `
-Wno-unused-result` (global), and cast to `void` (local).

Since It's unclear why we want so many toggle options for this feature, this
attribute doesn't change a user's program
<http://eel.is/c++draft/dcl.attr.nodiscard>, and users already have
two compiler-based
opt-out mechanisms <https://godbolt.org/z/hsWo1v5W9> for all supported
compilers and C++ standards, I think it's reasonable to remove this
attribute in favour of the easier-to-use attribute itself.

Kind regards,

Christopher Di Bella
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/libcxx-dev/attachments/20210513/891ec0d9/attachment.html>


More information about the libcxx-dev mailing list