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

Decomposer incorrectly casts subexpressions to bool #2938

Open
elbeno opened this issue Nov 27, 2024 · 0 comments
Open

Decomposer incorrectly casts subexpressions to bool #2938

elbeno opened this issue Nov 27, 2024 · 0 comments

Comments

@elbeno
Copy link

elbeno commented Nov 27, 2024

Describe the bug
The internal mechanism of the expression decomposer casts subexpressions to bool when they aren't necessarily convertible.
e.g. https://github.com/catchorg/Catch2/blob/devel/src/catch2/internal/catch_decomposer.hpp#L396

This is somewhat defensible for equality/comparison operators, but less defensible for operator| which is increasingly used as a pipeline operator.

Expected behavior
Expressions inside CHECK, REQUIRE, etc, should compile when the whole expression is convertible to bool.

Reproduction steps
Consider std::execution (P2300) - the following would cause a compile error:

CHECK(just(42) | then([] (auto i) { return i + 1; }) | sync_wait());

The whole expression evaluates to an optional which should be testable, but the subexpression just | then is a sender, not something convertible to bool.

Super simple example: https://compiler-explorer.com/z/v8dWxY474

Platform information:
Not platform-specific.

Additional context
Maybe overloading the bitwise operators is a historical choice? The workaround of course is always to put extra parens around the expression. But it's unfortunate, and is probably going to trip more people up in future (especially now that use cases are going into the standard).

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

No branches or pull requests

1 participant