LLVM  14.0.0git
MSVCErrorWorkarounds.h
Go to the documentation of this file.
1 //===--- MSVCErrorWorkarounds.h - Enable future<Error> in MSVC --*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // MSVC's promise/future implementation requires types to be default
10 // constructible, so this header provides analogues of Error an Expected
11 // that are default constructed in a safely destructible state.
12 //
13 // FIXME: Kill off this header and migrate all users to Error/Expected once we
14 // move to MSVC versions that support non-default-constructible types.
15 //
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef LLVM_SUPPORT_MSVCERRORWORKAROUNDS_H
19 #define LLVM_SUPPORT_MSVCERRORWORKAROUNDS_H
20 
21 #include "llvm/Support/Error.h"
22 
23 namespace llvm {
24 
25 // A default-constructible llvm::Error that is suitable for use with MSVC's
26 // std::future implementation which requires default constructible types.
27 class MSVCPError : public Error {
28 public:
29  MSVCPError() { (void)!!*this; }
30 
32 
35  return *this;
36  }
37 
38  MSVCPError(Error Err) : Error(std::move(Err)) {}
39 };
40 
41 // A default-constructible llvm::Expected that is suitable for use with MSVC's
42 // std::future implementation, which requires default constructible types.
43 template <typename T> class MSVCPExpected : public Expected<T> {
44 public:
47  consumeError(this->takeError());
48  }
49 
51 
54  return *this;
55  }
56 
57  MSVCPExpected(Error Err) : Expected<T>(std::move(Err)) {}
58 
59  template <typename OtherT>
61  OtherT &&Val,
62  std::enable_if_t<std::is_convertible<OtherT, T>::value> * = nullptr)
63  : Expected<T>(std::move(Val)) {}
64 
65  template <class OtherT>
67  Expected<OtherT> &&Other,
68  std::enable_if_t<std::is_convertible<OtherT, T>::value> * = nullptr)
69  : Expected<T>(std::move(Other)) {}
70 
71  template <class OtherT>
72  explicit MSVCPExpected(
73  Expected<OtherT> &&Other,
74  std::enable_if_t<!std::is_convertible<OtherT, T>::value> * = nullptr)
75  : Expected<T>(std::move(Other)) {}
76 };
77 
78 } // end namespace llvm
79 
80 #endif // LLVM_SUPPORT_MSVCERRORWORKAROUNDS_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::Expected::operator=
Expected & operator=(Expected &&Other)
Move-assign from another Expected<T>.
Definition: Error.h:546
Error.h
llvm::MSVCPExpected
Definition: MSVCErrorWorkarounds.h:43
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1045
llvm::MSVCPExpected::MSVCPExpected
MSVCPExpected(OtherT &&Val, std::enable_if_t< std::is_convertible< OtherT, T >::value > *=nullptr)
Definition: MSVCErrorWorkarounds.h:60
llvm::Error::operator=
Error & operator=(const Error &Other)=delete
llvm::MSVCPExpected::MSVCPExpected
MSVCPExpected(MSVCPExpected &&Other)
Definition: MSVCErrorWorkarounds.h:50
llvm::MSVCPExpected::operator=
MSVCPExpected & operator=(MSVCPExpected &&Other)
Definition: MSVCErrorWorkarounds.h:52
llvm::MSVCPExpected::MSVCPExpected
MSVCPExpected(Expected< OtherT > &&Other, std::enable_if_t<!std::is_convertible< OtherT, T >::value > *=nullptr)
Definition: MSVCErrorWorkarounds.h:72
llvm::MSVCPExpected::MSVCPExpected
MSVCPExpected(Error Err)
Definition: MSVCErrorWorkarounds.h:57
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1639
llvm::StringError
This class wraps a string in an Error.
Definition: Error.h:1218
llvm::MSVCPError
Definition: MSVCErrorWorkarounds.h:27
std
Definition: BitVector.h:838
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:77
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::MSVCPError::MSVCPError
MSVCPError(Error Err)
Definition: MSVCErrorWorkarounds.h:38
llvm::make_error
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition: Error.h:335
llvm::MSVCPError::MSVCPError
MSVCPError()
Definition: MSVCErrorWorkarounds.h:29
llvm::MSVCPExpected::MSVCPExpected
MSVCPExpected(Expected< OtherT > &&Other, std::enable_if_t< std::is_convertible< OtherT, T >::value > *=nullptr)
Definition: MSVCErrorWorkarounds.h:66
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:599
llvm::MSVCPError::operator=
MSVCPError & operator=(MSVCPError Other)
Definition: MSVCErrorWorkarounds.h:33
llvm::MSVCPError::MSVCPError
MSVCPError(MSVCPError &&Other)
Definition: MSVCErrorWorkarounds.h:31
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1191
llvm::MSVCPExpected::MSVCPExpected
MSVCPExpected()
Definition: MSVCErrorWorkarounds.h:45