Skip to content

Decomposer incorrectly casts subexpressions to bool #2938

Open
@elbeno

Description

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).

Activity

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions