Report a fatal error if ValOrErr is a failure value, otherwise unwraps and returns the contained reference.

Synopsis

Declared in <llvm/Support/Error.h>

template<typename T>
T&
cantFail(
    Expected<T&> ValOrErr,
    char const* Msg = nullptr);

Description

This function can be used to wrap calls to fallible functions ONLY when it is known that the Error will always be a success value. E.g.

// foo only attempts the fallible operation if DoFallibleOperation is
// true. If DoFallibleOperation is false then foo always returns a Bar&.
Expected<Bar&> foo(bool DoFallibleOperation);

Bar &X = cantFail(foo(false));

Return Value

The contained reference from ValOrErr.

Parameters

Name

Description

ValOrErr

Expected reference that must hold success.

Msg

Optional message used if ValOrErr is a failure.

Created with MrDocs