Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Apply the "safe bool" idiom to ConfigureQueueStatus #590

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/groups/bmq/bmqa/bmqa_configurequeuestatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigureQueueStatus>::BoolType BoolType;

// CREATORS

/// Default constructor, use the optionally specified `allocator`.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<ConfigureQueueStatus>::makeValue(
result() == bmqt::ConfigureQueueResult::e_SUCCESS);
}

inline const QueueId& ConfigureQueueStatus::queueId() const
Expand Down
Loading