diff --git a/include/gsl.h b/include/gsl.h index 1357d76..c7e7fcb 100644 --- a/include/gsl.h +++ b/include/gsl.h @@ -102,6 +102,7 @@ typename Cont::value_type& at(Cont& cont, size_t index) { fail_fast_assert(index template class not_null { + static_assert(std::is_pointer::value, "T must be a pointer type"); public: not_null(T t) : ptr_(t) { ensure_invariant(); } @@ -162,6 +163,7 @@ private: template class maybe_null_dbg { + static_assert(std::is_pointer::value, "T must be a pointer type"); public: maybe_null_dbg() : ptr_(nullptr), tested_(false) {} @@ -237,6 +239,7 @@ private: template class maybe_null_ret { + static_assert(std::is_pointer::value, "T must be a pointer type"); public: maybe_null_ret() : ptr_(nullptr) {} maybe_null_ret(std::nullptr_t) : ptr_(nullptr) {} diff --git a/tests/maybenull_tests.cpp b/tests/maybenull_tests.cpp index 0a9d891..10ac6b5 100644 --- a/tests/maybenull_tests.cpp +++ b/tests/maybenull_tests.cpp @@ -16,6 +16,7 @@ #include #include +#include using namespace Guide; @@ -27,6 +28,10 @@ SUITE(MaybeNullTests) { TEST(TestMaybeNull1) { +#ifdef CONFIRM_COMPILATION_ERRORS + maybe_null_dbg> f(std::vector{1}); // Not a pointer type. Must be tested with a non-integral type. + maybe_null_ret> g(std::vector{1}); // Not a pointer type. Must be tested with a non-integral type. +#endif int n = 5; maybe_null_dbg opt_n(&n); int result = 0; diff --git a/tests/notnull_tests.cpp b/tests/notnull_tests.cpp index 008cbb3..bf3e0e7 100644 --- a/tests/notnull_tests.cpp +++ b/tests/notnull_tests.cpp @@ -16,6 +16,7 @@ #include #include +#include using namespace Guide; @@ -48,6 +49,7 @@ SUITE(NotNullTests) not_null p; // yay...does not compile! std::unique_ptr up = std::make_unique(120); not_null p = up; + not_null> f(std::vector{1}); // Not a pointer type. Must be tested with a non-integral type. #endif int i = 12; auto rp = RefCounted(&i);