From 34c58c2c37c6af446f776e8e7433723665d2bc69 Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> Date: Tue, 28 Jan 2025 21:12:43 -0500 Subject: [PATCH] Apply safe bool idiom Signed-off-by: Vinay Deshmukh <32487576+vinay-deshmukh@users.noreply.github.com> --- src/groups/bmq/bmqa/bmqa_configurequeuestatus.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/groups/bmq/bmqa/bmqa_configurequeuestatus.h b/src/groups/bmq/bmqa/bmqa_configurequeuestatus.h index e00db146da..6eab90029f 100644 --- a/src/groups/bmq/bmqa/bmqa_configurequeuestatus.h +++ b/src/groups/bmq/bmqa/bmqa_configurequeuestatus.h @@ -76,6 +76,11 @@ class ConfigureQueueStatus { BSLMF_NESTED_TRAIT_DECLARATION(ConfigureQueueStatus, bslma::UsesBslmaAllocator) + // Use of an `UnspecifiedBool` to prevent implicit conversions to + // integral values, and comparisons between different classes which + // have boolean operators. + typedef bsls::UnspecifiedBool::BoolType BoolType; + // CREATORS /// Default constructor, use the optionally specified `allocator`. @@ -103,7 +108,7 @@ class ConfigureQueueStatus { // ACCESSORS /// Return true if this result indicates success, and false otherwise. - operator bool() const; + operator BoolType() const; /// Return the queueId associated to this operation result, if any. const QueueId& queueId() const; @@ -198,9 +203,10 @@ ConfigureQueueStatus::operator=(const ConfigureQueueStatus& other) } // ACCESSORS -inline ConfigureQueueStatus::operator bool() const +inline ConfigureQueueStatus::operator BoolType() const { - return result() == bmqt::ConfigureQueueResult::e_SUCCESS; + return bsls::UnspecifiedBool::makeValue( + result() == bmqt::ConfigureQueueResult::e_SUCCESS); } inline const QueueId& ConfigureQueueStatus::queueId() const