From 17690558c3ef6e6db850aa9f2993ea07467fe536 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 26 Oct 2023 17:08:55 -0400 Subject: cmUVHandlePtr: Add explicit conversion to bool --- Source/cmUVHandlePtr.cxx | 6 ++++++ Source/cmUVHandlePtr.h | 2 ++ Tests/CMakeLib/testUVRAII.cxx | 6 +++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Source/cmUVHandlePtr.cxx b/Source/cmUVHandlePtr.cxx index fd109a5..0e169df 100644 --- a/Source/cmUVHandlePtr.cxx +++ b/Source/cmUVHandlePtr.cxx @@ -97,6 +97,12 @@ void uv_handle_ptr_base_::allocate(void* data) } template +uv_handle_ptr_base_::operator bool() const +{ + return this->handle.get(); +} + +template void uv_handle_ptr_base_::reset() { this->handle.reset(); diff --git a/Source/cmUVHandlePtr.h b/Source/cmUVHandlePtr.h index afb7658..f5e2097 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 0bdd44c..ce11761 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; -- cgit v0.12