summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2017-05-03 14:17:02 -0400
committerMathias Stearn <mathias@10gen.com>2017-05-05 11:34:44 -0400
commitda55c9dd441b29d413450757f74f5da39f37a5c2 (patch)
tree48fd318d0ad5cbc15d73361910f6f452bd939e2e
parentea6788f9c835a2bc9fd33a17fb12d5aef3b4b7f1 (diff)
downloadmongo-da55c9dd441b29d413450757f74f5da39f37a5c2.tar.gz
SERVER-29047 Fix BSONObjBuilder's move constructor
-rw-r--r--src/mongo/bson/bsonmisc.h2
-rw-r--r--src/mongo/bson/bsonobjbuilder.h2
-rw-r--r--src/mongo/bson/bsonobjbuilder_test.cpp30
3 files changed, 17 insertions, 17 deletions
diff --git a/src/mongo/bson/bsonmisc.h b/src/mongo/bson/bsonmisc.h
index 7cf1bb4ac05..2ca9d39c805 100644
--- a/src/mongo/bson/bsonmisc.h
+++ b/src/mongo/bson/bsonmisc.h
@@ -204,6 +204,8 @@ inline BSONObj OR(const BSONObj& a,
// Utility class to implement BSON( key << val ) as described above.
class BSONObjBuilderValueStream {
+ MONGO_DISALLOW_COPYING(BSONObjBuilderValueStream);
+
public:
friend class Labeler;
BSONObjBuilderValueStream(BSONObjBuilder* builder);
diff --git a/src/mongo/bson/bsonobjbuilder.h b/src/mongo/bson/bsonobjbuilder.h
index 4840a0f7210..1ec71249d7d 100644
--- a/src/mongo/bson/bsonobjbuilder.h
+++ b/src/mongo/bson/bsonobjbuilder.h
@@ -129,7 +129,7 @@ public:
: _b(&other._b == &other._buf ? _buf : other._b),
_buf(std::move(other._buf)),
_offset(std::move(other._offset)),
- _s(std::move(other._s)),
+ _s(this), // Don't move from other._s because that will leave it pointing to other.
_tracker(std::move(other._tracker)),
_doneCalled(std::move(other._doneCalled)) {
other.abandon();
diff --git a/src/mongo/bson/bsonobjbuilder_test.cpp b/src/mongo/bson/bsonobjbuilder_test.cpp
index 3cc75b50560..bef67573661 100644
--- a/src/mongo/bson/bsonobjbuilder_test.cpp
+++ b/src/mongo/bson/bsonobjbuilder_test.cpp
@@ -331,34 +331,32 @@ TEST(BSONObjBuilderTest, ResetToEmptyForNestedBuilderOnlyResetsInnerObj) {
ASSERT_BSONOBJ_EQ(BSON("a" << 3 << "nestedObj" << BSONObj()), bob.obj());
}
-TEST(BSONObjBuilderTest, ReturningAnOwningBSONObjBuilderWorks) {
- BSONObjBuilder bob = ([] {
- BSONObjBuilder initial;
- initial.append("a", 1);
- return initial;
- })();
- ASSERT(bob.owned());
+TEST(BSONObjBuilderTest, MovingAnOwningBSONObjBuilderWorks) {
+ BSONObjBuilder initial;
+ initial.append("a", 1);
+ BSONObjBuilder bob(std::move(initial));
+ ASSERT(bob.owned());
bob.append("b", 2);
-
- ASSERT_BSONOBJ_EQ(bob.obj(), BSON("a" << 1 << "b" << 2));
+ bob << "c" << 3;
+ ASSERT_BSONOBJ_EQ(bob.obj(), BSON("a" << 1 << "b" << 2 << "c" << 3));
}
-TEST(BSONObjBuilderTest, ReturningANonOwningBSONObjBuilderWorks) {
+TEST(BSONObjBuilderTest, MovingANonOwningBSONObjBuilderWorks) {
BSONObjBuilder outer;
{
- BSONObjBuilder bob = ([&] {
- BSONObjBuilder initial(outer.subobjStart("nested"));
- initial.append("a", 1);
- return initial;
- })();
+ BSONObjBuilder initial(outer.subobjStart("nested"));
+ initial.append("a", 1);
+
+ BSONObjBuilder bob(std::move(initial));
ASSERT(!bob.owned());
ASSERT_EQ(&bob.bb(), &outer.bb());
bob.append("b", 2);
+ bob << "c" << 3;
}
- ASSERT_BSONOBJ_EQ(outer.obj(), BSON("nested" << BSON("a" << 1 << "b" << 2)));
+ ASSERT_BSONOBJ_EQ(outer.obj(), BSON("nested" << BSON("a" << 1 << "b" << 2 << "c" << 3)));
}
} // unnamed namespace