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::value, "T cannot be assigned nullptr."); template ::value>> - constexpr not_null(U&& u) : ptr_(std::forward(u)) + constexpr explicit not_null(U&& u) : ptr_(std::forward(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 u = &unrelated; + not_null u{&unrelated}; (void) u; - not_null p = &derived; - not_null q = &base; + not_null p{&derived}; + not_null q(&base); q = p; // allowed with heterogeneous copy ctor CHECK(q == p); @@ -192,18 +192,18 @@ TEST_CASE("TestNotNullCasting") not_null r = p; not_null s = reinterpret_cast(p); #endif - not_null t = reinterpret_cast(p.get()); + not_null t(reinterpret_cast(p.get())); CHECK(reinterpret_cast(p.get()) == reinterpret_cast(t.get())); } TEST_CASE("TestNotNullAssignment") { int i = 12; - not_null p = &i; + not_null p(&i); CHECK(helper(p)); int* q = nullptr; - CHECK_THROWS_AS(p = q, fail_fast); + CHECK_THROWS_AS(p = not_null(q), fail_fast); } TEST_CASE("TestNotNullRawPointerComparison")