Skip to content

modernize-use-nodiscard - #8452

Closed
Jacobfaib wants to merge 1 commit into
NVIDIA:mainfrom
Jacobfaib:jacobf/2026-04-15/modernize-use-nodiscard
Closed

Jacobfaib wants to merge 1 commit into
NVIDIA:mainfrom
Jacobfaib:jacobf/2026-04-15/modernize-use-nodiscard

Conversation

@Jacobfaib

Copy link
Copy Markdown
Contributor

Description

closes

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@Jacobfaib Jacobfaib self-assigned this Apr 15, 2026
@Jacobfaib
Jacobfaib requested review from a team as code owners April 15, 2026 15:55
@Jacobfaib
Jacobfaib requested a review from gonidelis April 15, 2026 15:55
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Apr 15, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Apr 15, 2026

@fbusato fbusato left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. It is important to not add [[nodiscard]] to member function or free-function that can change internal or parameter states

Comment thread cudax/examples/vector.cuh
}

::cuda::std::span<_Ty> transformed_argument() const
[[nodiscard]] ::cuda::std::span<_Ty> transformed_argument() const

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want the attribute even in the example? I'm not sure whether it's desired

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, do we have fully qualified names in examples ?!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be fiddly to disable this just for examples. I guess it's not the end of the world on the grounds that [[nodiscard]] is good hygiene and that our examples should proselytize this when possible, but if folks are strongly against it I can go about trying to disable it.

But beware it may end up with // NOLINT, which IMHO is the worse option for examples.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm probably fine with the change, just wanted to have a discussion about it :)

Comment on lines +52 to +57
[[nodiscard]] iterator begin() const
{
return PermutationIterator(first, TransformIterator(CountingIterator(0), repeat_functor(repeats)));
}

iterator end() const
[[nodiscard]] iterator end() const

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@bernhardmgruber

Copy link
Copy Markdown
Contributor

I think @gevtushenko concluded in the past that adding [[nodiscard]] to any public API is a source breaking change for users compiling with -Werror. At least that's the reason we are not adding nodiscard to CUB APIs until CCCL 4.0. This PR is adding nodiscard to public API functions. I would like to have @gevtushenko's opinion on the proposed changes.

@github-actions

This comment has been minimized.

@Jacobfaib
Jacobfaib force-pushed the jacobf/2026-04-15/modernize-use-nodiscard branch from b49f033 to 52b1fe3 Compare April 15, 2026 21:45
@github-actions

Copy link
Copy Markdown
Contributor

😬 CI Workflow Results

🟥 Finished in 4h 54m: Pass: 99%/428 | Total: 15d 09h | Max: 3h 17m | Hits: 69%/556380

See results here.

@gevtushenko

Copy link
Copy Markdown
Collaborator

I think @gevtushenko concluded in the past that adding [[nodiscard]] to any public API is a source breaking change for users compiling with -Werror. At least that's the reason we are not adding nodiscard to CUB APIs until CCCL 4.0. This PR is adding nodiscard to public API functions. I would like to have @gevtushenko's opinion on the proposed changes.

Thanks for pushing on this. I agree [[nodiscard]] is a good hygiene improvement and I'd like to see more of it in the codebase.

That said, we cannot retrofit it onto existing interfaces. Adding [[nodiscard]] to an already-released function is a source-breaking change for any downstream user compiling with warnings-as-errors, which is a pretty common setup. unfortunately, not checking the return value of CUB APIs is fairly common. So retrofitting [[nodiscard]] onto those APIs would very likely break someone on a minor version update.

Let's adopt [[nodiscard]] as the default for new interfaces going forward, and leave existing declarations as is until CCCL 4.0. It might be a good idea to start a tracker of what breaking changes we want to make and include [[nodiscard]] there.

@Jacobfaib Jacobfaib mentioned this pull request Apr 16, 2026
@Jacobfaib

Copy link
Copy Markdown
Contributor Author

Tabling until CCCL 4.0

@Jacobfaib Jacobfaib closed this Apr 16, 2026
@Jacobfaib
Jacobfaib deleted the jacobf/2026-04-15/modernize-use-nodiscard branch April 16, 2026 16:53
@bernhardmgruber

Copy link
Copy Markdown
Contributor

It might be a good idea to start a tracker of what breaking changes we want to make and include [[nodiscard]] there.

I am a year ahead: #3701

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants