Skip to content

[C++] Add short-circuit version of logical Status AND #32080

@asfimport

Description

@asfimport

Status overloads the & operator as in (from file_base.cc):


finished_.MarkFinished(dw_status & finish_st & tg_status);

However, it also sometimes used as (from scalar.cc):


return StdHash(s.value.days) & StdHash(s.value.milliseconds);

This latter form is technically correct (in this case) because StdHash has no side effects and there is no real need to short-circuit. However, this can be very misleading. The compiler is allowed to reorder these statements as it wants. This led to trouble in #13232 because I suggested something like...


return Foo(value) & Bar(std::move(value));

Now, for a C++ expert, this may have been immediately obvious. However, I think we can simplify things by adding the && operator for Status to allow:


return Foo(value) && Bar(std::move(value));

Reporter: Weston Pace / @westonpace

PRs and other links:

Note: This issue was originally created as ARROW-16743. Please see the migration documentation for further details.

Metadata

Metadata

Assignees

No one assigned

    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