[libcxx-commits] [PATCH] D152653: [libc++] Add [[nodiscard]] extensions to the functions in <bit>
Nikolas Klauser via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jun 12 12:20:07 PDT 2023
philnik marked an inline comment as done.
philnik added inline comments.
================
Comment at: libcxx/include/__bit/bit_floor.h:26
template <__libcpp_unsigned_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_floor(_Tp __t) noexcept {
+_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_floor(_Tp __t) noexcept {
return __t == 0 ? 0 : _Tp{1} << std::__bit_log2(__t);
----------------
Mordante wrote:
> philnik wrote:
> > Mordante wrote:
> > > These should be documented in `libcxx/docs/UsingLibcxx.rst`.
> > >
> > > Maybe we should look at a script/clang-tidy check to generate the documentation for these extensions.
> > IMO we should just remove the list, since I don't really see any use for it. A user doesn't care which functions are marked `[[nodiscard]]` unless the compiler complains (or doesn't complain if a `[[nodiscard]]` is missing), and implementers can just look at the code or the `*.nodiscard_externsions.*.cpp`. files or grep for `_LIBCPP_NODISCARD_EXT`.
> I strongly disagree. This is an extension and it should be documented.
> Actually I think it would be good to see whether it would be good to Standardize noexcept in more places in the Standard so we don't need extensions.
Arguably it's not. Compilers are allowed to warn on anything they want, and that's what we do here - just in the library instead of the compiler. Just because we use a standard attribute for it doesn't mean it's an extension. It's not like there is a meaningful difference between `[[nodiscard]]` and `[[clang:: warn_unused_result]]`. Regarding standardization - IMO that's wasted time. Implementations can add it at their leisure, which makes spending committee time on it basically useless. Furthermore, implementations don't even have to add it, since it's just recommended practice to issue a diagnostic: http://eel.is/c++draft/dcl.attr.nodiscard#4, making every `[[nodiscard]]` in the standard nothing more than loose guidance.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152653/new/
https://reviews.llvm.org/D152653
More information about the libcxx-commits
mailing list