/// T cannot be a rvalue reference.
template<class T>
class ErrorOr {
+ template <class OtherT> friend class ErrorOr;
static const bool isRef = is_reference<T>::value;
typedef ReferenceStorage<typename remove_reference<T>::type> wrap;
new (get()) storage_type(moveIfMoveConstructible<storage_type>(Val));
}
- ErrorOr(const ErrorOr &Other) : IsValid(false) {
+ template <class OtherT>
+ ErrorOr(ErrorOr<OtherT> &Other) : IsValid(false) {
// Construct an invalid ErrorOr if other is invalid.
if (!Other.IsValid)
return;
}
#if LLVM_HAS_RVALUE_REFERENCES
- ErrorOr(ErrorOr &&Other) : IsValid(false) {
+ template <class OtherT>
+ ErrorOr(ErrorOr<OtherT> &&Other) : IsValid(false) {
// Construct an invalid ErrorOr if other is invalid.
if (!Other.IsValid)
return;
return &Val->get();
}
-protected:
storage_type *get() {
assert(IsValid && "Can't do anything on a default constructed ErrorOr!");
assert(!HasError && "Cannot get value when an error exists!");
EXPECT_EQ(3, **t3());
#endif
}
+
+struct B {};
+struct D : B {};
+
+TEST(ErrorOr, Covariant) {
+ ErrorOr<B*> b(ErrorOr<D*>(0));
+
+#if LLVM_HAS_CXX11_STDLIB
+ ErrorOr<std::unique_ptr<B> > b1(ErrorOr<std::unique_ptr<D> >(0));
+#endif
+}
} // end anon namespace
struct InvalidArgError {