Skip to content

Fix cuda::constant_iterator return value#8260

Merged
davebayer merged 1 commit intoNVIDIA:mainfrom
miscco:fix_constant_iterator_reference
Apr 1, 2026
Merged

Fix cuda::constant_iterator return value#8260
davebayer merged 1 commit intoNVIDIA:mainfrom
miscco:fix_constant_iterator_reference

Conversation

@miscco
Copy link
Copy Markdown
Contributor

@miscco miscco commented Apr 1, 2026

We incorrectly returned const _Tp& from operator* and operator[]

This can lead to dangling references in pretty common code, such as cuda::std::reverse_iterator which does a return *::cuda::std::prev(__current_);

The temporary created by ::cuda::std::prev(__current_) is then dangling because we returned a reference to the value stored in the temporary iterator

Found during investigation of issues in #5649

We incorrectly returned `const _Tp&` from `operator*` and `operator[]`

This can lead to dangling references in pretty common code, such as `cuda::std::reverse_iterator` which does a `return *::cuda::std::prev(__current_);`

The temporary created by `::cuda::std::prev(__current_)` is then dangling because we returned a reference to the value stored in the temporary iterator
@miscco miscco requested a review from a team as a code owner April 1, 2026 15:22
@miscco miscco requested a review from griwes April 1, 2026 15:22
@github-project-automation github-project-automation bot moved this to Todo in CCCL Apr 1, 2026
@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Review in CCCL Apr 1, 2026
@davebayer davebayer enabled auto-merge (squash) April 1, 2026 16:05
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

🥳 CI Workflow Results

🟩 Finished in 1h 32m: Pass: 100%/99 | Total: 1d 13h | Max: 1h 15m | Hits: 92%/258659

See results here.

@davebayer davebayer merged commit a8db2de into NVIDIA:main Apr 1, 2026
117 of 120 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in CCCL Apr 1, 2026
gonidelis pushed a commit to gonidelis/cccl that referenced this pull request Apr 8, 2026
We incorrectly returned `const _Tp&` from `operator*` and `operator[]`

This can lead to dangling references in pretty common code, such as `cuda::std::reverse_iterator` which does a `return *::cuda::std::prev(__current_);`

The temporary created by `::cuda::std::prev(__current_)` is then dangling because we returned a reference to the value stored in the temporary iterator
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.

2 participants