LLVM  6.0.0svn
Public Member Functions | List of all members
llvm::ErrorAsOutParameter Class Reference

Helper for Errors used as out-parameters. More...

#include "llvm/Support/Error.h"

Public Member Functions

 ErrorAsOutParameter (Error *Err)
 ~ErrorAsOutParameter ()

Detailed Description

Helper for Errors used as out-parameters.

This helper is for use with the Error-as-out-parameter idiom, where an error is passed to a function or method by reference, rather than being returned. In such cases it is helpful to set the checked bit on entry to the function so that the error can be written to (unchecked Errors abort on assignment) and clear the checked bit on exit so that clients cannot accidentally forget to check the result. This helper performs these actions automatically using RAII:

Result foo(Error &Err) {
ErrorAsOutParameter ErrAsOutParam(&Err); // 'Checked' flag set
// <body of foo>
// <- 'Checked' flag auto-cleared when ErrAsOutParam is destructed.

ErrorAsOutParameter takes an Error* rather than Error& so that it can be used with optional Errors (Error pointers that are allowed to be null). If ErrorAsOutParameter took an Error reference, an instance would have to be created inside every condition that verified that Error was non-null. By taking an Error pointer we can just create one instance at the top of the function.

Definition at line 981 of file Error.h.

Constructor & Destructor Documentation

◆ ErrorAsOutParameter()

llvm::ErrorAsOutParameter::ErrorAsOutParameter ( Error Err)

Definition at line 983 of file Error.h.

◆ ~ErrorAsOutParameter()

llvm::ErrorAsOutParameter::~ErrorAsOutParameter ( )

Definition at line 989 of file Error.h.

References llvm::Error::success().

The documentation for this class was generated from the following file: