diff --git a/Source/cmUVHandlePtr.cxx b/Source/cmUVHandlePtr.cxx index fd109a516f..0e169dfcf2 100644 --- a/Source/cmUVHandlePtr.cxx +++ b/Source/cmUVHandlePtr.cxx @@ -96,6 +96,12 @@ void uv_handle_ptr_base_::allocate(void* data) this->handle->data = data; } +template +uv_handle_ptr_base_::operator bool() const +{ + return this->handle.get(); +} + template void uv_handle_ptr_base_::reset() { diff --git a/Source/cmUVHandlePtr.h b/Source/cmUVHandlePtr.h index afb7658ca0..f5e20974ce 100644 --- a/Source/cmUVHandlePtr.h +++ b/Source/cmUVHandlePtr.h @@ -130,6 +130,8 @@ public: uv_handle_ptr_base_(std::nullptr_t) {} ~uv_handle_ptr_base_() { this->reset(); } + explicit operator bool() const; + /** * Properly close the handle if needed and sets the inner handle to nullptr */ diff --git a/Tests/CMakeLib/testUVRAII.cxx b/Tests/CMakeLib/testUVRAII.cxx index 0bdd44c9de..ce11761200 100644 --- a/Tests/CMakeLib/testUVRAII.cxx +++ b/Tests/CMakeLib/testUVRAII.cxx @@ -37,7 +37,7 @@ static bool testAsyncShutdown() return false; } - if (signal.get()) { + if (signal) { std::cerr << "Loop exited with signal not being cleaned up" << std::endl; return false; } @@ -125,13 +125,13 @@ static bool testCrossAssignment() pipe.init(Loop, 0); cm::uv_stream_ptr stream = std::move(pipe); - if (pipe.get()) { + if (pipe) { std::cerr << "Move should be sure to invalidate the previous ptr" << std::endl; return false; } cm::uv_handle_ptr handle = std::move(stream); - if (stream.get()) { + if (stream) { std::cerr << "Move should be sure to invalidate the previous ptr" << std::endl; return false;