Skip to content

fix: enforce unexpected::operator== Mandates and fix its noexcept - #36

Open
ComixHe wants to merge 1 commit into
zeus-cpp:mainfrom
ComixHe:main
Open

ComixHe wants to merge 1 commit into
zeus-cpp:mainfrom
ComixHe:main

Conversation

@ComixHe

@ComixHe ComixHe commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

[expected.un.eq] mandates x.error() == y.error() be well-formed and its result be convertible to bool. Enforce it with a static_assert in the body so malformed comparisons get a clear diagnostic instead of obscure hard errors.

Also fix the noexcept specifier: noexcept(lhs.error() == rhs.error()) only inspected the comparison, ignoring the implicit result-to-bool conversion performed by the return statement, so the operator could be declared noexcept yet terminate at runtime on a throwing conversion.

Use expected_detail::is_nothrow_equality_result_convertible_to_bool_v, which covers the whole expression and matches the convention used by every other equality operator in this header.

[expected.un.eq] mandates x.error() == y.error() be well-formed and
its result be convertible to bool. Enforce it with a static_assert in
the body so malformed comparisons get a clear diagnostic instead of
obscure hard errors.

Also fix the noexcept specifier: noexcept(lhs.error() == rhs.error())
only inspected the comparison, ignoring the implicit result-to-bool
conversion performed by the return statement, so the operator could be
declared noexcept yet terminate at runtime on a throwing conversion.
Use expected_detail::is_nothrow_equality_result_convertible_to_bool_v,
which covers the whole expression and matches the convention used by
every other equality operator in this header.

Signed-off-by: Yuming He <ComixHe1895@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant