From 47fbb29ad79f403a8e11463169e2e4f7eadc8622 Mon Sep 17 00:00:00 2001 From: Brad King Date: Sat, 2 Dec 2023 06:37:40 -0500 Subject: cmUVHandlePtr: Fix conversion to bool on Oracle Studio compiler The operator added by commit 17690558c3 (cmUVHandlePtr: Add explicit conversion to bool, 2023-10-26) works in direct expressions like `if(foo)` but not compound expressions like `if(foo && ...)`. Drop the `explicit` mark when compiling with Oracle Studio so we can at least compile valid code. --- Source/cmUVHandlePtr.h | 8 ++++++++ Tests/CMakeLib/testUVHandlePtr.cxx | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Source/cmUVHandlePtr.h b/Source/cmUVHandlePtr.h index 1b5eb9c..b8b3491 100644 --- a/Source/cmUVHandlePtr.h +++ b/Source/cmUVHandlePtr.h @@ -132,7 +132,15 @@ public: uv_handle_ptr_base_(std::nullptr_t) {} ~uv_handle_ptr_base_() { this->reset(); } +#if defined(__SUNPRO_CC) + // The Oracle Studio compiler recognizes 'explicit operator bool()' in + // 'if(foo)' but not 'if(foo && ...)'. The purpose of 'explicit' here + // is to avoid accidental conversion in non-boolean contexts. Just + // leave it out on this compiler so we can compile valid code. + operator bool() const; +#else explicit operator bool() const; +#endif /** * Properly close the handle if needed and sets the inner handle to nullptr diff --git a/Tests/CMakeLib/testUVHandlePtr.cxx b/Tests/CMakeLib/testUVHandlePtr.cxx index c97d755..17f672d 100644 --- a/Tests/CMakeLib/testUVHandlePtr.cxx +++ b/Tests/CMakeLib/testUVHandlePtr.cxx @@ -7,6 +7,21 @@ #include "cmGetPipes.h" #include "cmUVHandlePtr.h" +static bool testBool() +{ + cm::uv_async_ptr async; + cm::uv_handle_ptr handle; + cm::uv_idle_ptr idle; + cm::uv_pipe_ptr pipe; + cm::uv_process_ptr process; + cm::uv_signal_ptr signal; + cm::uv_stream_ptr stream; + cm::uv_timer_ptr timer; + cm::uv_tty_ptr tty; + return !async && !handle && !idle && !pipe && !process && !signal && + !stream && !timer && !tty; +} + static bool testIdle() { bool idled = false; @@ -130,6 +145,7 @@ static bool testWriteCallback() int testUVHandlePtr(int, char** const) { bool passed = true; + passed = testBool() && passed; passed = testIdle() && passed; passed = testTimer() && passed; passed = testWriteCallback() && passed; -- cgit v0.12