Replace obsolete safe bool idiom with explicit operator bool 01/269401/2
authorArtur Świgoń <a.swigon@samsung.com>
Thu, 13 Jan 2022 14:28:08 +0000 (15:28 +0100)
committerArtur Świgoń <a.swigon@samsung.com>
Mon, 17 Jan 2022 09:27:10 +0000 (10:27 +0100)
C++11 introduces 'explicit operator bool' to prevent unintended implicit
conversions to 'bool', thus making the trick with converting to a
pointer-to-member (a.k.a. "safe bool idiom") obsolete.

The explicit operator is more restrictive than 'safe bool', and it
helped uncover a bug in the test suite where object handles were
implicitly converted to bool before being sent to an std::ostream.

Change-Id: I1128903e8f429d8903b5282d7c1bd4aa0be00979

automated-tests/src/dali-adaptor/dali-test-suite-utils/dali-test-suite-utils.cpp
automated-tests/src/dali-adaptor/dali-test-suite-utils/dali-test-suite-utils.h
automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.cpp
dali/internal/system/common/capture-impl.cpp

index 523bd8c..299a0e1 100644 (file)
@@ -78,6 +78,11 @@ std::ostream& operator<<(std::ostream& ostream, Degree angle)
   return ostream;
 }
 
+std::ostream& operator<<(std::ostream& ostream, BaseHandle handle)
+{
+  return ostream << static_cast<void*>(handle.GetObjectPtr());
+}
+
 void DALI_TEST_EQUALS(const BaseHandle& baseHandle1, const BaseHandle& baseHandle2, const char* location)
 {
   DALI_TEST_EQUALS<const BaseHandle&>(baseHandle1, baseHandle2, location);
index c6e63e7..a070298 100644 (file)
@@ -99,6 +99,7 @@ bool          operator==(TimePeriod a, TimePeriod b);
 std::ostream& operator<<(std::ostream& ostream, TimePeriod value);
 std::ostream& operator<<(std::ostream& ostream, Radian angle);
 std::ostream& operator<<(std::ostream& ostream, Degree angle);
+std::ostream& operator<<(std::ostream& ostream, BaseHandle handle);
 
 /**
  * Test whether two values are equal.
index d2d8b16..fb2afda 100644 (file)
@@ -78,7 +78,7 @@ std::ostream& operator<<(std::ostream& o, const Graphics::TextureCreateInfo& cre
     << " usageFlags:" << std::hex << createInfo.usageFlags
     << " data:" << std::hex << createInfo.data
     << " dataSize:" << std::dec << createInfo.dataSize
-    << " nativeImagePtr:" << std::hex << createInfo.nativeImagePtr;
+    << " nativeImagePtr:" << std::hex << createInfo.nativeImagePtr.Get();
   return o;
 }
 
index 1445ebb..21169fe 100644 (file)
@@ -180,7 +180,7 @@ void Capture::DeleteFrameBuffer()
 
 bool Capture::IsFrameBufferCreated()
 {
-  return mFrameBuffer;
+  return static_cast<bool>(mFrameBuffer);
 }
 
 void Capture::SetupRenderTask(const Dali::Vector2& position, const Dali::Vector2& size, Dali::Actor source, const Dali::Vector4& clearColor)