Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: thrust::optional<T&>::emplace() does not compile #1706

Closed
1 task done
Snektron opened this issue May 6, 2024 · 0 comments · Fixed by #1707
Closed
1 task done

[BUG]: thrust::optional<T&>::emplace() does not compile #1706

Snektron opened this issue May 6, 2024 · 0 comments · Fixed by #1707
Labels
bug Something isn't working right.

Comments

@Snektron
Copy link
Contributor

Snektron commented May 6, 2024

Is this a duplicate?

Type of Bug

Compile-time Error

Component

Thrust

Describe the bug

A recent change in clang revealed a problem in the implementation of thrust::optional<T&>::emplace(): it's calling this->construct(), which is not available on optional<T&>. Upon further investigation it seems that calling construct() here is not the right approach, as the address that the optional holds should be changed instead. This was reported as a bug to rocThrust, but it would be nice to have a fix upstream also.

See llvm/llvm-project#90152 and ROCm/rocThrust#404. I've implemented a fix downstream here: ROCm/rocThrust#405.

How to Reproduce

  1. See godbolt link below for exact reproducer
  2. Construct a thrust::optional<int&> (or any other optional holding a reference).
  3. Use the emplace() method
  4. Compilation fails with error message
thrust/optional.h(2756): error: class "thrust::optional<int &>" has no member "construct"
      this->construct(std::forward<Args>(args)...);
            ^
          detected during instantiation of "T &thrust::optional<T &>::emplace(Args &&...) [with T=int, Args=<int &>]" at line 12 of <source>

Expected behavior

From the implementation of the other operations in thrust::optional<T&>, it seems that emplace() on optional<T&> should replace the optional's value with the address of the operand, to construct a new T&, rather than try to construct a new T.

Reproduction link

https://godbolt.org/z/359cvPso1

Operating System

No response

nvidia-smi output

No response

NVCC version

No response

@Snektron Snektron added the bug Something isn't working right. label May 6, 2024
@github-project-automation github-project-automation bot moved this to Todo in CCCL May 6, 2024
@Snektron Snektron changed the title [BUG]: [BUG]: thrust::optional<T&>::emplace() does not compile May 6, 2024
@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Review in CCCL May 6, 2024
@github-project-automation github-project-automation bot moved this from In Review to Done in CCCL May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant