<html><head></head><body><div>Hi all,</div><div><br></div><div>I saw that some methods that was returning ErrorOr<> object are now returning Expected<> object embedding Error object instead of std::error_code. I have some troubles understanding how to use the new Error class...</div><div><br></div><div>Until now, I was using this kind of code :</div><div><br></div><blockquote type="cite"><div>auto BinOrErr = llvm::object::createBinary(this->execPath);</div><div><br></div><div>if(auto EC = BinOrErr.getError())</div><div>{</div><div>   errs() << "Error : " << EC.message() << "\n";</div><div><div>   return false;</div></div><div>}</div></blockquote><div><br></div><div>And this one:</div><div><br></div><blockquote type="cite"><div>auto CoverageOrErr = llvm::coverage::CoverageMapping::load(this->execPath, this->profPath, arch);</div><div><br></div><div>if (auto EC = CoverageOrErr.getError())</div><div>{</div><div>   errs() << "Error: Failed to load coverage: " << EC.message() << "\n";</div><div>   return false;</div><div>}</div></blockquote><div><br></div><div>Since LLVM 3.9, load() and createBinary() return an Expected object. I managed to get the Error object using takeError() method (instead of the old getError()). But, since the Error object is not an std::error_code, I did not found a way to retrieve the message information... I tried to convert the Error object back to std::error_code using the function errorToErrorCode() like this:</div><div><br></div><blockquote type="cite"><div>auto CoverageOrErr = llvm::coverage::CoverageMapping::load(this->execPath, this->profPath, arch);</div><div><br></div><div>if (Error Err = CoverageOrErr.takeError())</div><div>{</div><div>   errs() << "Error: Failed to load coverage: " << errorToErrorCode(Err).message() << "\n";</div><div>   return false;</div><div>}</div></blockquote><div><br></div><div>But I cannot compile this code because of the copy constructor being marked as deleted.</div><div><br></div><blockquote type="cite"><div>error: use of deleted function ‘llvm::Error::Error(const llvm::Error&)’</div><div>/home/gagou/test/llvm/include/llvm/Support/Error.h:161:3: note: declared here</div><div>   Error(const Error &Other) = delete;</div></blockquote><div><br></div><div>I don't know what I'm doing wrong, other files like SymbolizableObjectFile.cpp, ObjectFile.cpp IRObjectFile.cpp, etc seems to use the function errorToErrorCode() without any issue.</div><div><br></div><div>Does anyone know what is the best way to retrieve the message information from an Error object?</div><div><br></div><div>Thank you !</div><div><br></div><div>Regards,</div><div>Gael</div><div><br></div><div><br></div><div><br></div></body></html>