Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:32

0001 //===--- MSVCErrorWorkarounds.h - Enable future<Error> in MSVC --*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // MSVC's promise/future implementation requires types to be default
0010 // constructible, so this header provides analogues of Error an Expected
0011 // that are default constructed in a safely destructible state.
0012 //
0013 // FIXME: Kill off this header and migrate all users to Error/Expected once we
0014 //        move to MSVC versions that support non-default-constructible types.
0015 //
0016 //===----------------------------------------------------------------------===//
0017 
0018 #ifndef LLVM_SUPPORT_MSVCERRORWORKAROUNDS_H
0019 #define LLVM_SUPPORT_MSVCERRORWORKAROUNDS_H
0020 
0021 #include "llvm/Support/Error.h"
0022 
0023 namespace llvm {
0024 
0025 // A default-constructible llvm::Error that is suitable for use with MSVC's
0026 // std::future implementation which requires default constructible types.
0027 class MSVCPError : public Error {
0028 public:
0029   MSVCPError() { (void)!!*this; }
0030 
0031   MSVCPError(MSVCPError &&Other) : Error(std::move(Other)) {}
0032 
0033   MSVCPError &operator=(MSVCPError Other) {
0034     Error::operator=(std::move(Other));
0035     return *this;
0036   }
0037 
0038   MSVCPError(Error Err) : Error(std::move(Err)) {}
0039 };
0040 
0041 // A default-constructible llvm::Expected that is suitable for use with MSVC's
0042 // std::future implementation, which requires default constructible types.
0043 template <typename T> class MSVCPExpected : public Expected<T> {
0044 public:
0045   MSVCPExpected()
0046       : Expected<T>(make_error<StringError>("", inconvertibleErrorCode())) {
0047     consumeError(this->takeError());
0048   }
0049 
0050   MSVCPExpected(MSVCPExpected &&Other) : Expected<T>(std::move(Other)) {}
0051 
0052   MSVCPExpected &operator=(MSVCPExpected &&Other) {
0053     Expected<T>::operator=(std::move(Other));
0054     return *this;
0055   }
0056 
0057   MSVCPExpected(Error Err) : Expected<T>(std::move(Err)) {}
0058 
0059   template <typename OtherT>
0060   MSVCPExpected(
0061       OtherT &&Val,
0062       std::enable_if_t<std::is_convertible<OtherT, T>::value> * = nullptr)
0063       : Expected<T>(std::move(Val)) {}
0064 
0065   template <class OtherT>
0066   MSVCPExpected(
0067       Expected<OtherT> &&Other,
0068       std::enable_if_t<std::is_convertible<OtherT, T>::value> * = nullptr)
0069       : Expected<T>(std::move(Other)) {}
0070 
0071   template <class OtherT>
0072   explicit MSVCPExpected(
0073       Expected<OtherT> &&Other,
0074       std::enable_if_t<!std::is_convertible<OtherT, T>::value> * = nullptr)
0075       : Expected<T>(std::move(Other)) {}
0076 };
0077 
0078 } // end namespace llvm
0079 
0080 #endif // LLVM_SUPPORT_MSVCERRORWORKAROUNDS_H