Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/GSL.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Malov <alexey.malov@cpslabs.net>2017-05-31 21:18:55 +0300
committerNeil MacIntosh <neilmac@microsoft.com>2017-05-31 21:18:55 +0300
commit247c4250d40d362953f5566d1527576c6c0ba352 (patch)
treeb574f84d360def2fdc9f76149e52a6942811ab12 /tests/notnull_tests.cpp
parent30595c1f1d8bd481b2a7658323fa42e5f9a44029 (diff)
Fixes dereferencing operator issue #517 introduced in PR #513 (#516)
* Fixes issue with dereferencing operator issue #491 introduced in PR #513 dereferencing operator added in PR#513 returned a copy of the object instead of reference to it. Adding decltype(auto) as return type of operator* fixes this issue. * added more tests for not_null::operator*
Diffstat (limited to 'tests/notnull_tests.cpp')
-rw-r--r--tests/notnull_tests.cpp49
1 files changed, 37 insertions, 12 deletions
diff --git a/tests/notnull_tests.cpp b/tests/notnull_tests.cpp
index 85ed5b5..caab476 100644
--- a/tests/notnull_tests.cpp
+++ b/tests/notnull_tests.cpp
@@ -95,6 +95,16 @@ std::string operator>=(CustomPtr<T> const& lhs, CustomPtr<U> const& rhs)
: "false";
}
+struct NonCopyableNonMovable
+{
+ NonCopyableNonMovable() = default;
+ NonCopyableNonMovable(const NonCopyableNonMovable&) = delete;
+ NonCopyableNonMovable& operator=(const NonCopyableNonMovable&) = delete;
+ NonCopyableNonMovable(NonCopyableNonMovable&&) = delete;
+ NonCopyableNonMovable& operator=(NonCopyableNonMovable&&) = delete;
+};
+
+
SUITE(NotNullTests)
{
@@ -253,18 +263,33 @@ SUITE(NotNullTests)
TEST(TestNotNullDereferenceOperator)
{
- auto sp1 = std::make_shared<int>(42);
-
- using NotNullSp1 = not_null<decltype(sp1)>;
-
- CHECK(*NotNullSp1(sp1) == *sp1);
-
- int ints[1] = {42};
- CustomPtr<int> p1(&ints[0]);
-
- using NotNull1 = not_null<decltype(p1)>;
- CHECK(*NotNull1(p1) == 42);
- }
+ {
+ auto sp1 = std::make_shared<NonCopyableNonMovable>();
+
+ using NotNullSp1 = not_null<decltype(sp1)>;
+ CHECK(typeid(*sp1) == typeid(*NotNullSp1(sp1)));
+ CHECK(std::addressof(*NotNullSp1(sp1)) == std::addressof(*sp1));
+ }
+
+ {
+ int ints[1] = { 42 };
+ CustomPtr<int> p1(&ints[0]);
+
+ using NotNull1 = not_null<decltype(p1)>;
+ CHECK(typeid(*NotNull1(p1)) == typeid(*p1));
+ CHECK(*NotNull1(p1) == 42);
+ *NotNull1(p1) = 43;
+ CHECK(ints[0] == 43);
+ }
+
+ {
+ int v = 42;
+ gsl::not_null<int*> p(&v);
+ CHECK(typeid(*p) == typeid(*(&v)));
+ *p = 43;
+ CHECK(v == 43);
+ }
+ }
}
int main(int, const char* []) { return UnitTest::RunAllTests(); }