LLVM  3.7.0
Public Types | Public Member Functions | Friends | List of all members
llvm::ErrorOr< T > Class Template Reference

Represents either an error or a value T. More...

#include <ErrorOr.h>

Collaboration diagram for llvm::ErrorOr< T >:
[legend]

Public Types

typedef std::conditional
< isRef, wrap, T >::type 
storage_type
 

Public Member Functions

template<class E >
 ErrorOr (E ErrorCode, typename std::enable_if< std::is_error_code_enum< E >::value||std::is_error_condition_enum< E >::value, void * >::type=0)
 
 ErrorOr (std::error_code EC)
 
 ErrorOr (T Val)
 
 ErrorOr (const ErrorOr &Other)
 
template<class OtherT >
 ErrorOr (const ErrorOr< OtherT > &Other, typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *=nullptr)
 
template<class OtherT >
 ErrorOr (const ErrorOr< OtherT > &Other, typename std::enable_if< !std::is_convertible< OtherT, const T & >::value >::type *=nullptr)
 
 ErrorOr (ErrorOr &&Other)
 
template<class OtherT >
 ErrorOr (ErrorOr< OtherT > &&Other, typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *=nullptr)
 
template<class OtherT >
 ErrorOr (ErrorOr< OtherT > &&Other, typename std::enable_if<!std::is_convertible< OtherT, T >::value >::type *=nullptr)
 
ErrorOroperator= (const ErrorOr &Other)
 
ErrorOroperator= (ErrorOr &&Other)
 
 ~ErrorOr ()
 
 operator bool () const
 Return false if there is an error. More...
 
reference get ()
 
const_reference get () const
 
std::error_code getError () const
 
pointer operator-> ()
 
reference operator* ()
 

Friends

template<class OtherT >
class ErrorOr
 

Detailed Description

template<class T>
class llvm::ErrorOr< T >

Represents either an error or a value T.

ErrorOr<T> is a pointer-like class that represents the result of an operation. The result is either an error, or a value of type T. This is designed to emulate the usage of returning a pointer where nullptr indicates failure. However instead of just knowing that the operation failed, we also have an error_code and optional user data that describes why it failed.

It is used like the following.

ErrorOr<Buffer> getBuffer();
auto buffer = getBuffer();
if (error_code ec = buffer.getError())
return ec;
buffer->write("adena");

Implicit conversion to bool returns true if there is a usable value. The unary * and -> operators provide pointer like access to the value. Accessing the value when there is an error has undefined behavior.

When T is a reference type the behaivor is slightly different. The reference is held in a std::reference_wrapper<std::remove_reference<T>::type>, and there is special handling to make operator -> work as if T was not a reference.

T cannot be a rvalue reference.

Definition at line 82 of file ErrorOr.h.

Member Typedef Documentation

template<class T>
typedef std::conditional<isRef, wrap, T>::type llvm::ErrorOr< T >::storage_type

Definition at line 88 of file ErrorOr.h.

Constructor & Destructor Documentation

template<class T>
template<class E >
llvm::ErrorOr< T >::ErrorOr ( ErrorCode,
typename std::enable_if< std::is_error_code_enum< E >::value||std::is_error_condition_enum< E >::value, void * >::type  = 0 
)
inline

Definition at line 97 of file ErrorOr.h.

References llvm::make_error_code().

template<class T>
llvm::ErrorOr< T >::ErrorOr ( std::error_code  EC)
inline

Definition at line 105 of file ErrorOr.h.

template<class T>
llvm::ErrorOr< T >::ErrorOr ( T  Val)
inline

Definition at line 109 of file ErrorOr.h.

template<class T>
llvm::ErrorOr< T >::ErrorOr ( const ErrorOr< T > &  Other)
inline

Definition at line 113 of file ErrorOr.h.

template<class T>
template<class OtherT >
llvm::ErrorOr< T >::ErrorOr ( const ErrorOr< OtherT > &  Other,
typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *  = nullptr 
)
inline

Definition at line 118 of file ErrorOr.h.

template<class T>
template<class OtherT >
llvm::ErrorOr< T >::ErrorOr ( const ErrorOr< OtherT > &  Other,
typename std::enable_if< !std::is_convertible< OtherT, const T & >::value >::type *  = nullptr 
)
inlineexplicit

Definition at line 126 of file ErrorOr.h.

template<class T>
llvm::ErrorOr< T >::ErrorOr ( ErrorOr< T > &&  Other)
inline

Definition at line 133 of file ErrorOr.h.

References Other.

template<class T>
template<class OtherT >
llvm::ErrorOr< T >::ErrorOr ( ErrorOr< OtherT > &&  Other,
typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *  = nullptr 
)
inline

Definition at line 138 of file ErrorOr.h.

References Other.

template<class T>
template<class OtherT >
llvm::ErrorOr< T >::ErrorOr ( ErrorOr< OtherT > &&  Other,
typename std::enable_if<!std::is_convertible< OtherT, T >::value >::type *  = nullptr 
)
inlineexplicit

Definition at line 148 of file ErrorOr.h.

References Other.

template<class T>
llvm::ErrorOr< T >::~ErrorOr ( )
inline

Definition at line 165 of file ErrorOr.h.

Member Function Documentation

template<class T>
reference llvm::ErrorOr< T >::get ( )
inline
template<class T>
const_reference llvm::ErrorOr< T >::get ( ) const
inline

Definition at line 176 of file ErrorOr.h.

template<class T>
std::error_code llvm::ErrorOr< T >::getError ( ) const
inline

Definition at line 178 of file ErrorOr.h.

Referenced by llvm::object::Archive::Archive(), llvm::LTOCodeGenerator::compileOptimized(), llvm::SpecialCaseList::create(), llvm::object::IRObjectFile::create(), llvm::object::createBinary(), llvm::LTOModule::createFromFile(), llvm::LTOModule::createFromOpenFileSlice(), llvm::object::ObjectFile::createObjectFile(), llvm::DiffFilesWithTolerance(), llvm::DWARFContextInMemory::DWARFContextInMemory(), llvm::object::ELFFile< ELFT >::ELFFile(), llvm::RuntimeDyldImpl::emitCommonSymbols(), llvm::object::IRObjectFile::findBitcodeInMemBuffer(), llvm::object::Archive::findSym(), llvm::MCJIT::findSymbol(), llvm::object::Archive::Child::getAsBinary(), llvm::object::COFFObjectFile::getAuxSymbol(), llvm::object::Archive::Child::getBuffer(), llvm::object::ELFFile< ELFT >::getEntry(), llvm::getLazyIRFileModule(), getLazyIRModule(), llvm::object::Archive::Child::getMemoryBufferRef(), llvm::getOffset(), llvm::object::ELFObjectFile< ELFT >::getRelocatedSection(), llvm::object::ELFFile< ELFT >::getRelocationSymbol(), llvm::RuntimeDyldMachO::getRelocationValueRef(), llvm::object::ELFObjectFile< ELFT >::getSectionName(), llvm::object::ELFObjectFile< ELFT >::getSymbolAddress(), llvm::object::ELFObjectFile< ELFT >::getSymbolSection(), llvm::object::ELFFile< ELFT >::getSymbolVersion(), LLVMCreateMemoryBufferWithContentsOfFile(), LLVMCreateMemoryBufferWithSTDIN(), LLVMGetBitcodeModuleInContext(), LLVMGetSymbolAddress(), LLVMGetSymbolName(), LLVMParseBitcodeInContext(), llvm::RuntimeDyldImpl::loadObjectImpl(), llvm::SymbolRewriter::RewriteMapParser::parse(), llvm::parseAssemblyFile(), parseBitcodeFileImpl(), llvm::parseIR(), llvm::parseIRFile(), llvm::RuntimeDyldMachO::populateIndirectSymbolPointersSection(), llvm::object::ObjectFile::printSymbolName(), llvm::RuntimeDyldCOFFX86_64::processRelocationRef(), llvm::RuntimeDyldELF::processRelocationRef(), llvm::object::ELFObjectFile< ELFT >::section_rel_begin(), setupMemoryBuffer(), llvm::TableGenMain(), and llvm::writeArchive().

template<class T>
llvm::ErrorOr< T >::operator bool ( ) const
inlineexplicit

Return false if there is an error.

Definition at line 171 of file ErrorOr.h.

template<class T>
reference llvm::ErrorOr< T >::operator* ( )
inline

Definition at line 186 of file ErrorOr.h.

template<class T>
pointer llvm::ErrorOr< T >::operator-> ( )
inline

Definition at line 182 of file ErrorOr.h.

template<class T>
ErrorOr& llvm::ErrorOr< T >::operator= ( const ErrorOr< T > &  Other)
inline

Definition at line 155 of file ErrorOr.h.

template<class T>
ErrorOr& llvm::ErrorOr< T >::operator= ( ErrorOr< T > &&  Other)
inline

Definition at line 160 of file ErrorOr.h.

References Other.

Friends And Related Function Documentation

template<class T>
template<class OtherT >
friend class ErrorOr
friend

Definition at line 83 of file ErrorOr.h.

Member Data Documentation

template<class T>
AlignedCharArrayUnion<std::error_code> llvm::ErrorOr< T >::ErrorStorage

Definition at line 275 of file ErrorOr.h.

template<class T>
AlignedCharArrayUnion<storage_type> llvm::ErrorOr< T >::TStorage

Definition at line 274 of file ErrorOr.h.


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