Details
- Reviewers
ldionne Mordante - Group Reviewers
Restricted Project - Commits
- rG7d3bba5e2fe6: [libc++] Add [[nodiscard]] extensions to the functions in <bit>
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libcxx/include/__bit/bit_ceil.h | ||
---|---|---|
20 | Can you update the list in libcxx/docs/UsingLibcxx.rst? |
Thanks for working on this!
libcxx/include/__bit/bit_floor.h | ||
---|---|---|
26 | 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. | |
libcxx/include/__bit/countr.h | ||
26–34 | These would make sense to, doesn't even need to be an extension. | |
libcxx/include/__bit/rotate.h | ||
37 | These should be nodiscard unconditionally. http://eel.is/c++draft/bit#rotate ... I've no clue what makes these two functions special. | |
libcxx/test/libcxx/diagnostics/bit.nodiscard_extensions.compile.pass.cpp | ||
20 | Please add bit_cast too; it's already marked, but not tested. |
Address comments
libcxx/include/__bit/bit_floor.h | ||
---|---|---|
26 | 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. |
LGTM modulo one nit.
libcxx/docs/UsingLibcxx.rst | ||
---|---|---|
407–412 | FYI I landed D152097 today, this fixed the ordering of this list. So there might be some merge conflicts. | |
449–450 | These are not extensions | |
libcxx/include/__bit/bit_floor.h | ||
26 | I strongly disagree. This is an extension and it should be documented. |
libcxx/include/__bit/bit_floor.h | ||
---|---|---|
26 | 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. |
FYI I landed D152097 today, this fixed the ordering of this list. So there might be some merge conflicts.