diff options
author | Kern Handa <kern.handa@gmail.com> | 2015-09-25 19:41:40 +0300 |
---|---|---|
committer | Kern Handa <kern.handa@gmail.com> | 2015-09-27 22:35:23 +0300 |
commit | 2b6d90436f3f0b0444efc918203663367e823b65 (patch) | |
tree | 760330fd90e6d70e1bcf8a06c5b9e45f73e81f81 /tests/notnull_tests.cpp | |
parent | 599a354b1c02c2e93693692e2ada02105c105ff9 (diff) |
not_null and maybe_null variants should only work on nullptr-assignable types.
This is in accordance with the GSL.View guidance on not_null and maybe_null
types in the CppCoreGuidelines document.
Diffstat (limited to 'tests/notnull_tests.cpp')
-rw-r--r-- | tests/notnull_tests.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/notnull_tests.cpp b/tests/notnull_tests.cpp index 008cbb3..7232840 100644 --- a/tests/notnull_tests.cpp +++ b/tests/notnull_tests.cpp @@ -16,6 +16,7 @@ #include <UnitTest++/UnitTest++.h> #include <gsl.h> +#include <vector> using namespace Guide; @@ -48,11 +49,18 @@ SUITE(NotNullTests) not_null<int*> p; // yay...does not compile! std::unique_ptr<int> up = std::make_unique<int>(120); not_null<int*> p = up; + + // Forbid non-nullptr assignable types + not_null<std::vector<int>> f(std::vector<int>{1}); + not_null<int> z(10); + not_null<std::vector<int>> y({1,2}); #endif int i = 12; auto rp = RefCounted<int>(&i); not_null<int*> p(rp); CHECK(p.get() == &i); + + not_null<std::shared_ptr<int>> x(std::make_shared<int>(10)); // shared_ptr<int> is nullptr assignable } TEST(TestNotNullCasting) |