Skip to content

[libcu++] Implement P3798R1 The unexpected in std::expected#9733

Open
davebayer wants to merge 1 commit into
NVIDIA:mainfrom
davebayer:optional_has_error
Open

[libcu++] Implement P3798R1 The unexpected in std::expected#9733
davebayer wants to merge 1 commit into
NVIDIA:mainfrom
davebayer:optional_has_error

Conversation

@davebayer

Copy link
Copy Markdown
Contributor

This PR implements P3798R1 and backports it to C++17.

@davebayer davebayer requested a review from a team as a code owner July 7, 2026 15:38
@davebayer davebayer requested a review from Jacobfaib July 7, 2026 15:38
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jul 7, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jul 7, 2026
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 7a57d342-97b2-4311-a221-18bcb4732a81

📥 Commits

Reviewing files that changed from the base of the PR and between 332a726 and ae15777.

📒 Files selected for processing (4)
  • libcudacxx/include/cuda/std/__expected/expected.h
  • libcudacxx/include/cuda/std/version
  • libcudacxx/test/libcudacxx/std/utilities/expected/expected.expected/observers/has_error.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/expected/expected.void/observers/has_error.pass.cpp

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added a new has_error() observer for cuda::std::expected and cuda::std::expected<void, E> to quickly check whether a value is absent.
    • Updated the library feature version to reflect the new expected capability.
  • Tests

    • Added coverage for has_error() in both value and void specializations, including constexpr and noexcept behavior.

Walkthrough

Adds a has_error() observer method to cuda::std::expected<T, E> and its expected<void, E> specialization, returning the negation of has_value(). Updates the __cccl_lib_expected feature-test macro version. Adds corresponding test files validating behavior and noexcept qualification for both specializations.

Changes

has_error() observer addition

Layer / File(s) Summary
has_error() implementation and version macro
libcudacxx/include/cuda/std/__expected/expected.h, libcudacxx/include/cuda/std/version
Adds constexpr bool has_error() const noexcept returning !__has_val_ to both expected<T, E> and expected<void, E>; bumps __cccl_lib_expected from 202211L to 202606L.
expected<T,E> has_error() tests
libcudacxx/test/.../expected.expected/observers/has_error.pass.cpp
New test validates has_error() runtime behavior for error/value states, checks noexcept qualification via a detection trait, and optionally runs a constexpr static_assert.
expected<void,E> has_error() tests
libcudacxx/test/.../expected.void/observers/has_error.pass.cpp
New test with headers/includes validates has_error() noexcept qualification and runtime/constexpr behavior for expected<void, int> in error and default states.

Sequence Diagram(s)

Not applicable — changes are simple accessor additions and test files without multi-component interaction flows.

Estimated code review effort: Low

Suggested labels: libcudacxx, feature, test

Suggested reviewers: none identified from provided data

important: verify has_error() is documented/added to the public spec/changelog for expected, not just the feature-test macro bump.

suggestion: consider adding a symmetric noexcept static_assert test for the general expected<T,E> case matching the void specialization's Foo trait check, if not already covered.

🐰 A hare hopped through expected's den,
found has_value's shadow, named it again —
"has_error," it chirped, noexcept and neat,
tests confirm the trick is complete.


Comment @coderabbitai help to get the list of available commands.

return this->__has_val_;
}

_CCCL_API constexpr bool has_error() const noexcept

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.

Suggested change
_CCCL_API constexpr bool has_error() const noexcept
[[nodiscard]] _CCCL_API constexpr bool has_error() const noexcept

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 want to make a separate PR adding [[nodiscard]] to expected

return this->__has_val_;
}

_CCCL_API constexpr bool has_error() const noexcept

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.

Suggested change
_CCCL_API constexpr bool has_error() const noexcept
[[nodiscard]] _CCCL_API constexpr bool has_error() const noexcept

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

😬 CI Workflow Results

🟥 Finished in 4h 27m: Pass: 96%/120 | Total: 5d 02h | Max: 3h 21m | Hits: 66%/562010

See results here.

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

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

3 participants