Skip to content

Shared::operator bool returns the opposite of handle validity #26

Description

@jeet-dekivadia

I noticed that Shared::operator bool() appears to be inverted:

Awaitable* get() const;
explicit operator bool() const { return !state_; }

That makes a default-constructed Shared evaluate true, while a constructed Shared with a valid state evaluates false. This is the opposite of the surrounding handle-like API: get() returns nullptr for the empty case, closed() treats an empty Shared as closed, and IntrusivePtr itself uses ptr_ != nullptr for its boolean conversion.

A small example of the observable behavior:

auto shared = Shared([]() -> Task<int> { co_return 42; });
CATCH_CHECK(shared); // currently fails

decltype(shared) empty;
CATCH_CHECK(!empty); // currently fails

I have a small fix with a regression in the existing shared tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions