This class represents an efficient way to signal success or failure. It should be preferred over the use of bool when appropriate, as it avoids all of the ambiguity that arises in interpreting a boolean result. This class is marked as NODISCARD to ensure that the result is processed. Users may explicitly discard a result by using (void), e.g. (void)functionThatReturnsALogicalResult();. Given the intended nature of this class, it generally shouldn't be used as the result of functions that very frequently have the result ignored. This class is intended to be used in conjunction with the utility functions below.

Synopsis

Declared in <llvm/Support/LogicalResult.h>

struct [[nodiscard]] LogicalResult;

Member Functions

Name

Description

failed

Returns true if the provided LogicalResult corresponds to a failure value.

succeeded

Returns true if the provided LogicalResult corresponds to a success value.

Static Member Functions

Name

Description

failure

If isFailure is true a failure result is generated, otherwise a 'success' result is generated.

success

If isSuccess is true a success result is generated, otherwise a 'failure' result is generated.

Non-Member Functions

Name

Description

failed

Utility function that returns true if the provided LogicalResult corresponds to a failure value.

failure

Utility function to generate a LogicalResult. If isFailure is true a failure result is generated, otherwise a 'success' result is generated.

succeeded

Utility function that returns true if the provided LogicalResult corresponds to a success value.

success

Utility function to generate a LogicalResult. If isSuccess is true a success result is generated, otherwise a 'failure' result is generated.

Derived Classes

Name

Description

ParseResult

This class represents success/failure for parsing‐like operations that find it important to chain together failable operations with ||. This is an extended version of LogicalResult that allows for explicit conversion to bool.

Return Value

Note

The return value should not be discarded.

Created with MrDocs