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

Tagged union holding either a T or a Error. More...

#include "llvm/Support/CachePruning.h"

Inheritance diagram for llvm::Expected< T >:
Inheritance graph
[legend]
Collaboration diagram for llvm::Expected< T >:
Collaboration graph
[legend]

Public Types

using storage_type = typename std::conditional< isRef, wrap, T >::type
 
using value_type = T
 

Public Member Functions

 Expected (Error Err)
 Create an Expected<T> error value from the given Error. More...
 
 Expected (ErrorSuccess)=delete
 Forbid to convert from Error::success() implicitly, this avoids having Expected<T> foo() { return Error::success(); } which compiles otherwise but triggers the assertion above. More...
 
template<typename OtherT >
 Expected (OtherT &&Val, typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *=nullptr)
 Create an Expected<T> success value from the given OtherT value, which must be convertible to T. More...
 
 Expected (Expected &&Other)
 Move construct an Expected<T> value. More...
 
template<class OtherT >
 Expected (Expected< OtherT > &&Other, typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *=nullptr)
 Move construct an Expected<T> value from an Expected<OtherT>, where OtherT must be convertible to T. More...
 
template<class OtherT >
 Expected (Expected< OtherT > &&Other, typename std::enable_if<!std::is_convertible< OtherT, T >::value >::type *=nullptr)
 Move construct an Expected<T> value from an Expected<OtherT>, where OtherT isn't convertible to T. More...
 
Expectedoperator= (Expected &&Other)
 Move-assign from another Expected<T>. More...
 
 ~Expected ()
 Destroy an Expected<T>. More...
 
 operator bool ()
 Return false if there is an error. More...
 
reference get ()
 Returns a reference to the stored T value. More...
 
const_reference get () const
 Returns a const reference to the stored T value. More...
 
template<typename ErrT >
bool errorIsA () const
 Check that this Expected<T> is an error of type ErrT. More...
 
Error takeError ()
 Take ownership of the stored error. More...
 
pointer operator-> ()
 Returns a pointer to the stored T value. More...
 
const_pointer operator-> () const
 Returns a const pointer to the stored T value. More...
 
reference operator* ()
 Returns a reference to the stored T value. More...
 
const_reference operator* () const
 Returns a const reference to the stored T value. More...
 

Friends

template<class T1 >
class ExpectedAsOutParameter
 
template<class OtherT >
class Expected
 

Detailed Description

template<class T>
class llvm::Expected< T >

Tagged union holding either a T or a Error.

This class parallels ErrorOr, but replaces error_code with Error. Since Error cannot be copied, this class replaces getError() with takeError(). It also adds an bool errorIsA<ErrT>() method for testing the error class type.

Definition at line 23 of file CachePruning.h.

Member Typedef Documentation

◆ storage_type

template<class T>
using llvm::Expected< T >::storage_type = typename std::conditional<isRef, wrap, T>::type

Definition at line 445 of file Error.h.

◆ value_type

template<class T>
using llvm::Expected< T >::value_type = T

Definition at line 446 of file Error.h.

Constructor & Destructor Documentation

◆ Expected() [1/6]

template<class T>
llvm::Expected< T >::Expected ( Error  Err)
inline

Create an Expected<T> error value from the given Error.

Definition at line 456 of file Error.h.

◆ Expected() [2/6]

template<class T>
llvm::Expected< T >::Expected ( ErrorSuccess  )
delete

Forbid to convert from Error::success() implicitly, this avoids having Expected<T> foo() { return Error::success(); } which compiles otherwise but triggers the assertion above.

◆ Expected() [3/6]

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

Create an Expected<T> success value from the given OtherT value, which must be convertible to T.

Definition at line 475 of file Error.h.

◆ Expected() [4/6]

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

Move construct an Expected<T> value.

Definition at line 488 of file Error.h.

References Other.

◆ Expected() [5/6]

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

Move construct an Expected<T> value from an Expected<OtherT>, where OtherT must be convertible to T.

Definition at line 493 of file Error.h.

References Other.

◆ Expected() [6/6]

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

Move construct an Expected<T> value from an Expected<OtherT>, where OtherT isn't convertible to T.

Definition at line 502 of file Error.h.

References Other.

◆ ~Expected()

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

Destroy an Expected<T>.

Definition at line 516 of file Error.h.

Member Function Documentation

◆ errorIsA()

template<class T>
template<typename ErrT >
bool llvm::Expected< T >::errorIsA ( ) const
inline

Check that this Expected<T> is an error of type ErrT.

Definition at line 545 of file Error.h.

◆ get() [1/2]

template<class T>
reference llvm::Expected< T >::get ( )
inline

◆ get() [2/2]

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

Returns a const reference to the stored T value.

Definition at line 539 of file Error.h.

◆ operator bool()

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

Return false if there is an error.

Definition at line 525 of file Error.h.

◆ operator*() [1/2]

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

Returns a reference to the stored T value.

Definition at line 573 of file Error.h.

◆ operator*() [2/2]

template<class T>
const_reference llvm::Expected< T >::operator* ( ) const
inline

Returns a const reference to the stored T value.

Definition at line 579 of file Error.h.

References assert(), llvm::dbgs(), LLVM_ATTRIBUTE_NOINLINE, LLVM_ATTRIBUTE_NORETURN, LLVM_UNLIKELY, llvm::ErrorInfoBase::log(), Other, and T1.

◆ operator->() [1/2]

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

Returns a pointer to the stored T value.

Definition at line 561 of file Error.h.

◆ operator->() [2/2]

template<class T>
const_pointer llvm::Expected< T >::operator-> ( ) const
inline

Returns a const pointer to the stored T value.

Definition at line 567 of file Error.h.

◆ operator=()

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

Move-assign from another Expected<T>.

Definition at line 510 of file Error.h.

References Other.

Referenced by llvm::MSVCPExpected< T >::operator=().

◆ takeError()

template<class T>
Error llvm::Expected< T >::takeError ( )
inline

Take ownership of the stored error.

After calling this the Expected<T> is in an indeterminate state that can only be safely destructed. No further calls (beside the destructor) should be made on the Expected<T> vaule.

Definition at line 553 of file Error.h.

References llvm::Error, and llvm::Error::success().

Referenced by llvm::pdb::PDBFileBuilder::addInjectedSource(), llvm::pdb::PDBFileBuilder::addNamedStream(), llvm::object::ELFFile< ELFT >::android_relas(), llvm::lto::backend(), llvm::pdb::PDBFileBuilder::commit(), llvm::msf::MSFBuilder::commit(), computeMemberData(), llvm::orc::rpc::detail::ResultTraits< RetT >::consumeAbandoned(), llvm::object::SectionRef::containsSymbol(), llvm::GlobPattern::create(), llvm::symbolize::SymbolizableObjectFile::create(), llvm::object::IRObjectFile::create(), llvm::lto::InputFile::create(), llvm::object::createBinary(), llvm::mca::InstrBuilder::createInstruction(), createOnDiskBuffer(), llvm::DWARFContext::defaultErrorHandler(), llvm::dlltoolDriverMain(), doImportingForModule(), llvm::coverage::CounterMappingContext::dump(), llvm::object::ELFFile< ELFT >::dynamicEntries(), llvm::object::RelocVisitor::error(), llvm::coverage::CounterMappingContext::evaluate(), llvm::expectedToErrorOrAndEmitErrors(), llvm::pdb::GSIStreamBuilder::finalizeMsfLayout(), llvm::RuntimeDyldMachOX86_64::finalizeSection(), llvm::RuntimeDyldMachOI386::finalizeSection(), llvm::RuntimeDyldMachOAArch64::finalizeSection(), llvm::object::IRObjectFile::findBitcodeInMemBuffer(), llvm::pdb::TpiStream::findFullDeclForForwardRef(), llvm::MCJIT::findSymbol(), llvm::pdb::SymbolCache::findSymbolByTypeIndex(), llvm::symbolize::LLVMSymbolizer::flush(), forceRenaming(), llvm::DWARFDebugAranges::generate(), llvm::MCJIT::generateCodeForModule(), llvm::object::Archive::Child::getAsBinary(), llvm::object::COFFObjectFile::getAuxSymbol(), llvm::getBitcodeFileContents(), llvm::getBitcodeLTOInfo(), llvm::getBitcodeProducerString(), llvm::getBitcodeTargetTriple(), llvm::object::Archive::Child::getBuffer(), getDbiStreamPtr(), llvm::object::Archive::Child::getFullName(), llvm::IndexedInstrProfReader::getFunctionCounts(), llvm::getLazyBitcodeModule(), llvm::DWARFContext::getLineTableForUnit(), llvm::BitcodeModule::getLTOInfo(), llvm::object::Archive::Child::getMemoryBufferRef(), llvm::getModuleSummaryIndex(), llvm::object::ArchiveMemberHeader::getName(), llvm::object::Archive::Child::getName(), llvm::object::Archive::Child::getNext(), llvm::getOffset(), llvm::NewArchiveMember::getOldMember(), llvm::LTOModule::getProducerString(), llvm::object::Archive::Child::getRawSize(), getSingleModule(), llvm::object::Archive::Child::getSize(), llvm::pdb::PDBFile::getStringTable(), getSymbolInfo(), llvm::object::MachOObjectFile::getSymbolType(), handleNonPrevailingComdat(), llvm::pdb::PDBFile::hasPDBStringTable(), llvm::isBitcodeContainingObjCCategory(), llvm::LTOModule::isBitcodeFile(), llvm::LTOModule::isBitcodeForTarget(), llvm::LTOModule::isThinLTO(), llvm::isThumbFunc(), LLVMCreateObjectFile(), LLVMGetSymbolAddress(), LLVMGetSymbolName(), LLVMMoveToContainingSection(), llvm::lto::localCache(), llvm::parseBitcodeFile(), parseBitcodeFileImpl(), parseHexOcta(), printDwarfFileDirective(), llvm::object::ObjectFile::printSymbolName(), llvm::RuntimeDyldCOFFI386::processRelocationRef(), llvm::RuntimeDyldCOFFThumb::processRelocationRef(), llvm::RuntimeDyldELF::processRelocationRef(), llvm::RuntimeDyldCOFFX86_64::processRelocationRef(), llvm::object::readIRSymtab(), llvm::readModuleSummaryIndex(), llvm::orc::RemoteObjectLayer< RPCEndpoint >::remoteToJITSymbol(), llvm::orc::rpc::detail::RespondHelper< true >::sendResult(), llvm::orc::OrcMCJITReplacement::setProcessAllSections(), sumEdgeCount(), llvm::object::SymbolicFile::SymbolicFile(), llvm::detail::TakeExpected(), llvm::lto::thinBackend(), upgrade(), and llvm::writeArchive().

Friends And Related Function Documentation

◆ Expected

template<class T>
template<class OtherT >
friend class Expected
friend

Definition at line 436 of file Error.h.

◆ ExpectedAsOutParameter

template<class T>
template<class T1 >
friend class ExpectedAsOutParameter
friend

Definition at line 435 of file Error.h.

Member Data Documentation

◆ ErrorStorage

template<class T>
AlignedCharArrayUnion<error_type> llvm::Expected< T >::ErrorStorage

Definition at line 678 of file Error.h.

◆ TStorage

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

Definition at line 677 of file Error.h.


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