[libcxx-commits] [libcxx] WIP [libc++][ranges] Applied [[nodiscard]] to `transform_view` (PR #204014)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 17 02:05:26 PDT 2026


frederick-vs-ja wrote:

> Another question: I have marked the `operator==` as `nodiscard` in the context:
> 
> ```c++
>   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr bool
>   operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) {
>     return __x.__current_ == __y.__end_;
>   }
> ```
> 
> I know this shouldn't be allowed as per the Coding Guidelines, but I think semantically here it would make sense given the narrower semantics of sentinel comparisons - i.e. the pure usage of `while (it != end)`. Given the current tests we have are passing, do you think this should be allowed? Please let me know if I should either keep or remove it.

Let's remove it. Currently, Clang is already warning on discarding the result of this `operator==` (and use via `!=`). [Godbolt link](https://godbolt.org/z/j4bahT3T6).

> If you agree/disagree, could you please review the remaining attributes I've added? Then I can write the tests for the `transform` (expand the existing ones) based on the other PRs and I think we should be good to go.

The additions (except for `operator==`) look good to me.

Then, I think we should
- rename `libcxx/test/libcxx/ranges/range.adaptors/range.transform/adaptor.nodiscard.verify.cpp` to `nodicard.verify.cpp`, and then
- add test cases to the file.

In order to test all functions marked `[[nodiscard]]`, we should use some non-common and non-simple range (i.e. whose non-`const` and `const` versions of `begin` and `end` functions have four different return types).

https://github.com/llvm/llvm-project/pull/204014


More information about the libcxx-commits mailing list