LLVM 20.0.0git
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 (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.
}
Helper for Errors used as out-parameters.
Definition: Error.h:1130
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160

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 1130 of file Error.h.

Constructor & Destructor Documentation

◆ ErrorAsOutParameter() [1/2]

llvm::ErrorAsOutParameter::ErrorAsOutParameter ( Error Err)
inline

Definition at line 1133 of file Error.h.

◆ ErrorAsOutParameter() [2/2]

llvm::ErrorAsOutParameter::ErrorAsOutParameter ( Error Err)
inline

Definition at line 1139 of file Error.h.

◆ ~ErrorAsOutParameter()

llvm::ErrorAsOutParameter::~ErrorAsOutParameter ( )
inline

Definition at line 1143 of file Error.h.

References llvm::Error::success().


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