diff options
author | ericLemanissier <ericLemanissier@users.noreply.github.com> | 2018-04-25 04:11:43 +0200 |
---|---|---|
committer | Anna Gringauze <annagrin@microsoft.com> | 2018-04-24 19:11:43 -0700 |
commit | 2fc94db3ebfb1b066edeafac1837f34d6111bff4 (patch) | |
tree | b183a4a7a522b8f75e9902e0223e4f2a87d80c0b | |
parent | fbe867a9c4ea74650a76f4a2dd8b5a0eee3c79c1 (diff) | |
download | platform_external_Microsoft-GSL-2fc94db3ebfb1b066edeafac1837f34d6111bff4.tar.gz platform_external_Microsoft-GSL-2fc94db3ebfb1b066edeafac1837f34d6111bff4.tar.bz2 platform_external_Microsoft-GSL-2fc94db3ebfb1b066edeafac1837f34d6111bff4.zip |
not_null constructor is now explicit (#659)
solves #395
-rw-r--r-- | include/gsl/pointers | 2 | ||||
-rw-r--r-- | tests/notnull_tests.cpp | 12 |
2 files changed, 7 insertions, 7 deletions
diff --git a/include/gsl/pointers b/include/gsl/pointers index b2804a3..ad15ce3 100644 --- a/include/gsl/pointers +++ b/include/gsl/pointers @@ -72,7 +72,7 @@ public: static_assert(std::is_assignable<T&, std::nullptr_t>::value, "T cannot be assigned nullptr."); template <typename U, typename = std::enable_if_t<std::is_convertible<U, T>::value>> - constexpr not_null(U&& u) : ptr_(std::forward<U>(u)) + constexpr explicit not_null(U&& u) : ptr_(std::forward<U>(u)) { Expects(ptr_ != nullptr); } diff --git a/tests/notnull_tests.cpp b/tests/notnull_tests.cpp index a7ef27e..fa99bb7 100644 --- a/tests/notnull_tests.cpp +++ b/tests/notnull_tests.cpp @@ -178,10 +178,10 @@ TEST_CASE("TestNotNullCasting") MyBase base; MyDerived derived; Unrelated unrelated; - not_null<Unrelated*> u = &unrelated; + not_null<Unrelated*> u{&unrelated}; (void) u; - not_null<MyDerived*> p = &derived; - not_null<MyBase*> q = &base; + not_null<MyDerived*> p{&derived}; + not_null<MyBase*> q(&base); q = p; // allowed with heterogeneous copy ctor CHECK(q == p); @@ -192,18 +192,18 @@ TEST_CASE("TestNotNullCasting") not_null<Unrelated*> r = p; not_null<Unrelated*> s = reinterpret_cast<Unrelated*>(p); #endif - not_null<Unrelated*> t = reinterpret_cast<Unrelated*>(p.get()); + not_null<Unrelated*> t(reinterpret_cast<Unrelated*>(p.get())); CHECK(reinterpret_cast<void*>(p.get()) == reinterpret_cast<void*>(t.get())); } TEST_CASE("TestNotNullAssignment") { int i = 12; - not_null<int*> p = &i; + not_null<int*> p(&i); CHECK(helper(p)); int* q = nullptr; - CHECK_THROWS_AS(p = q, fail_fast); + CHECK_THROWS_AS(p = not_null<int*>(q), fail_fast); } TEST_CASE("TestNotNullRawPointerComparison") |