mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Fix issue #49
This commit is contained in:
parent
27ff004e84
commit
a46d6fcf0d
@ -223,12 +223,12 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
template <typename U, typename Dummy = std::enable_if_t<std::is_convertible<U, T>::value>>
|
template <typename U, typename Dummy = std::enable_if_t<std::is_convertible<U, T>::value>>
|
||||||
maybe_null_dbg(const maybe_null_dbg<U> &other) : ptr_(other.get()), tested_(false) {}
|
maybe_null_dbg(const maybe_null_dbg<U> &other) : ptr_(other.ptr_), tested_(false) {}
|
||||||
|
|
||||||
template <typename U, typename Dummy = std::enable_if_t<std::is_convertible<U, T>::value>>
|
template <typename U, typename Dummy = std::enable_if_t<std::is_convertible<U, T>::value>>
|
||||||
maybe_null_dbg& operator=(const maybe_null_dbg<U> &other)
|
maybe_null_dbg& operator=(const maybe_null_dbg<U> &other)
|
||||||
{
|
{
|
||||||
ptr_ = other.get();
|
ptr_ = other.ptr_;
|
||||||
tested_ = false;
|
tested_ = false;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -256,7 +256,8 @@ SUITE(MaybeNullTests)
|
|||||||
CHECK(p1.get() != nullptr);
|
CHECK(p1.get() != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TestMaybeNullAssignmentOps)
|
template<class maybe_null_type>
|
||||||
|
void TestMaybeNullAssignmentOpsHelper()
|
||||||
{
|
{
|
||||||
MyBase base;
|
MyBase base;
|
||||||
MyDerived derived;
|
MyDerived derived;
|
||||||
@ -266,32 +267,53 @@ SUITE(MaybeNullTests)
|
|||||||
not_null<MyDerived*> nnDerived(&derived);
|
not_null<MyDerived*> nnDerived(&derived);
|
||||||
not_null<Unrelated*> nnUnrelated(&unrelated);
|
not_null<Unrelated*> nnUnrelated(&unrelated);
|
||||||
|
|
||||||
maybe_null_ret<MyBase*> mnBase_ret1(&base), mnBase_ret2;
|
maybe_null_type::type<MyBase*> mnBase_ret1(&base), mnBase_ret2;
|
||||||
mnBase_ret2 = mnBase_ret1; // maybe_null_ret<T> = maybe_null_ret<T>
|
mnBase_ret2 = mnBase_ret1; // maybe_null_ret<T> = maybe_null_ret<T>
|
||||||
mnBase_ret2 = nnBase; // maybe_null_ret<T> = not_null<T>
|
mnBase_ret2 = nnBase; // maybe_null_ret<T> = not_null<T>
|
||||||
|
|
||||||
maybe_null_ret<MyDerived*> mnDerived_ret(&derived);
|
maybe_null_type::type<MyDerived*> mnDerived_ret(&derived);
|
||||||
mnBase_ret2 = mnDerived_ret; // maybe_null_ret<T> = maybe_null_ret<U>
|
mnBase_ret2 = mnDerived_ret; // maybe_null_ret<T> = maybe_null_ret<U>
|
||||||
mnBase_ret1 = &derived; // maybe_null_ret<T> = U;
|
mnBase_ret1 = &derived; // maybe_null_ret<T> = U;
|
||||||
mnBase_ret1 = nnDerived; // maybe_null_ret<T> = not_null<U>
|
mnBase_ret1 = nnDerived; // maybe_null_ret<T> = not_null<U>
|
||||||
|
|
||||||
maybe_null_ret<Unrelated*> mnUnrelated_ret;
|
maybe_null_type::type<Unrelated*> mnUnrelated_ret;
|
||||||
mnUnrelated_ret = &unrelated; // maybe_null_ret<T> = T
|
mnUnrelated_ret = &unrelated; // maybe_null_ret<T> = T
|
||||||
|
|
||||||
maybe_null_dbg<MyBase*> mnBase_dbg1(&base), mnBase_dbg2;
|
maybe_null_type::type<MyBase*> mnBase_dbg1(&base), mnBase_dbg2;
|
||||||
mnBase_dbg2 = mnBase_dbg1; // maybe_null_dbg<T> = maybe_null_dbg<T>
|
mnBase_dbg2 = mnBase_dbg1; // maybe_null_dbg<T> = maybe_null_dbg<T>
|
||||||
mnBase_dbg2 = nnBase; // maybe_null_dbg<T> = not_null<T>
|
mnBase_dbg2 = nnBase; // maybe_null_dbg<T> = not_null<T>
|
||||||
|
|
||||||
maybe_null_dbg<MyDerived*> mnDerived_dbg(&derived);
|
maybe_null_type::type<MyDerived*> mnDerived_dbg(&derived);
|
||||||
CHECK(mnDerived_dbg.present());
|
CHECK(mnDerived_dbg.present());
|
||||||
mnBase_dbg2 = mnDerived_dbg; // maybe_null_dbg<T> = maybe_null_dbg<U>
|
mnBase_dbg2 = mnDerived_dbg; // maybe_null_dbg<T> = maybe_null_dbg<U>
|
||||||
|
|
||||||
mnBase_dbg1 = &derived; // maybe_null_dbg<T> = U;
|
mnBase_dbg1 = &derived; // maybe_null_dbg<T> = U;
|
||||||
mnBase_dbg1 = nnDerived; // maybe_null_dbg<T> = not_null<U>
|
mnBase_dbg1 = nnDerived; // maybe_null_dbg<T> = not_null<U>
|
||||||
|
|
||||||
maybe_null_dbg<Unrelated*> mnUnrelated_dbg;
|
maybe_null_type::type<Unrelated*> mnUnrelated_dbg;
|
||||||
mnUnrelated_dbg = &unrelated; // maybe_null_dbg<T> = T
|
mnUnrelated_dbg = &unrelated; // maybe_null_dbg<T> = T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct maybe_null_ret_type
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
using type = maybe_null_ret<T>;
|
||||||
|
};
|
||||||
|
struct maybe_null_dbg_type
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
using type = maybe_null_dbg<T>;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(TestMaybeNullRetAssignmentOps)
|
||||||
|
{
|
||||||
|
TestMaybeNullAssignmentOpsHelper<maybe_null_ret_type>();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(TestMaybeNullDbgAssignmentOps)
|
||||||
|
{
|
||||||
|
TestMaybeNullAssignmentOpsHelper<maybe_null_dbg_type>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int, const char *[])
|
int main(int, const char *[])
|
||||||
|
Loading…
Reference in New Issue
Block a user