Skip to content

Commit 596cd59

Browse files
committed
Fix[mqbblp]: Fix build on Solaris
This patch fixes a build error on Solaris/C++03: the new `ElectorEventFunctor` constructor takes a `bslmf::MovableRef<bmqp::Event>`, which in C++11 is an alias for `bmqp::Event&&`. In C++03, though, temporary objects are not automatically converted into `MovableRef`s, resulting in an invocation of the `createInplace` function template to fail instantiation. We solve this by explicitly calling `bslmf::MovableRefUtil::move` on this temporary, which is a no-op in C++11 but a necessary call in C++03. Signed-off-by: Patrick M. Niedzielski <[email protected]>
1 parent a818cc6 commit 596cd59

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/groups/bmq/bmqp/bmqp_event.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include <bsl_string.h>
5353
#include <bslma_allocator.h>
5454
#include <bslma_usesbslmaallocator.h>
55+
#include <bslmf_movableref.h>
5556
#include <bslmf_nestedtraitdeclaration.h>
5657
#include <bsls_assert.h>
5758
#include <bsls_performancehint.h>
@@ -133,11 +134,21 @@ class Event {
133134
/// specified `allocator`.
134135
Event(const Event& src, bslma::Allocator* allocator = 0);
135136

137+
/// Create a new `bmqp::Event` instance having the same contents as the
138+
/// specified `original` object, leaving `original` in a valid but
139+
/// unspecified state. Optionally specify an `allocator` used to supply
140+
/// memory. If `allocator` is 0, the default memory allocator is used.
141+
Event(bslmf::MovableRef<Event> src, bslma::Allocator* allocator = 0);
142+
136143
// MANIPULATORS
137144

138145
/// Assignment operator of the specified `rhs`.
139146
Event& operator=(const Event& rhs);
140147

148+
/// Replace the contents of `*this` with those of `rhs`, leaving `rhs` in a
149+
/// valid but unspecified state. Return `*this`.
150+
Event& operator=(bslmf::MovableRef<Event> rhs);
151+
141152
/// Reset this Event to use the specified `blob`. If the optionally
142153
/// specified `clone` is true, this object will clone the blob into its
143154
/// internal shared pointer.
@@ -390,6 +401,15 @@ inline Event::Event(const Event& src, bslma::Allocator* allocator)
390401
initialize(src.d_blob_p, false);
391402
}
392403

404+
inline Event::Event(bslmf::MovableRef<Event> src, bslma::Allocator* allocator)
405+
: d_allocator_p(allocator)
406+
, d_clonedBlob_sp(0, allocator)
407+
, d_blob_p(0)
408+
{
409+
d_clonedBlob_sp = bslmf::MovableRefUtil::access(src).d_clonedBlob_sp;
410+
initialize(bslmf::MovableRefUtil::access(src).d_blob_p, false);
411+
}
412+
393413
inline Event& Event::operator=(const Event& rhs)
394414
{
395415
if (this != &rhs) {
@@ -399,6 +419,15 @@ inline Event& Event::operator=(const Event& rhs)
399419
return *this;
400420
}
401421

422+
inline Event& Event::operator=(bslmf::MovableRef<Event> rhs)
423+
{
424+
if (this != &bslmf::MovableRefUtil::access(rhs)) {
425+
d_clonedBlob_sp = bslmf::MovableRefUtil::access(rhs).d_clonedBlob_sp;
426+
initialize(bslmf::MovableRefUtil::access(rhs).d_blob_p, false);
427+
}
428+
return *this;
429+
}
430+
402431
inline void Event::reset(const bdlbb::Blob* blob, bool clone)
403432
{
404433
// PRECONDITIONS

src/groups/mqb/mqbblp/mqbblp_clusterorchestrator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <bsl_string.h>
4545
#include <bsl_vector.h>
4646
#include <bsla_annotations.h>
47+
#include <bslmf_movableref.h>
4748
#include <bsls_assert.h>
4849
#include <bsls_timeinterval.h>
4950

@@ -1272,10 +1273,11 @@ void ClusterOrchestrator::processElectorEvent(const bmqp::Event& event,
12721273

12731274
(*clusterEvent).setType(mqbi::DispatcherEventType::e_CALLBACK);
12741275

1276+
bmqp::Event clonedEvent = event.clone(d_allocator_p);
12751277
clusterEvent->callback()
12761278
.createInplace<ClusterOrchestrator::OnElectorEventFunctor>(
12771279
this,
1278-
event.clone(d_allocator_p),
1280+
bslmf::MovableRefUtil::move(clonedEvent),
12791281
source);
12801282

12811283
dispatcher()->dispatchEvent(clusterEvent, d_cluster_p);

0 commit comments

Comments
 (0)