Skip to content

Commit

Permalink
modify
Browse files Browse the repository at this point in the history
  • Loading branch information
bluehero committed Aug 7, 2017
1 parent 8ba1f84 commit 5fb0659
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 1 addition & 3 deletions include/rapidjson/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -2168,8 +2168,7 @@ class GenericDocument : public GenericValue<Encoding, Allocator> {
}
#endif

// Allow assignment from ValueType.
// Refer to Effective C++ 3rd Edition/Item 33: Avoid hiding inherited names.
// Allow assignment like a ValueType.
using ValueType::operator=;

//! Exchange the contents of this document with those of another.
Expand All @@ -2188,7 +2187,6 @@ class GenericDocument : public GenericValue<Encoding, Allocator> {
}

// Allow Swap from ValueType.
// Refer to Effective C++ 3rd Edition/Item 33: Avoid hiding inherited names.
using ValueType::Swap;

//! free-standing swap function helper
Expand Down
12 changes: 10 additions & 2 deletions test/unittest/documenttest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,17 +661,25 @@ TYPED_TEST(DocumentMove, MoveAssignmentStack) {

// Issue 22: Memory corruption via operator= from Document
// Fixed by making unimplemented assignment operator private.
// Prohibit assignment from Document, But allow assignment from Value
// Prohibit assignment from Document.
// But allow assignment from ValueType/int/double/..., like a ValueType
TEST(Document, Assignment) {
// Document d1;
// Document d2;
// d1 = d2;

Value x(1234);
Document d;

Value x(1234);
d = x;
EXPECT_TRUE(x.IsNull()); // move semantic
EXPECT_EQ(1234, d.GetInt());

d = 1;
EXPECT_EQ(1, d.GetInt());

d = 12.34;
EXPECT_NEAR(12.34, d.GetDouble(), 0.0);
}

#ifdef __clang__
Expand Down

0 comments on commit 5fb0659

Please sign in to comment.