diff options
author | Milo Yip <miloyip@gmail.com> | 2018-01-26 05:59:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-26 05:59:11 +0300 |
commit | 7641af690eb1996a15143b53fd675be6c3e11078 (patch) | |
tree | 8b642de7f5a7ebefb080d8393c939fb70bdbf34b | |
parent | cdc899a3f3b918bcdcdc262ac4c4861e63d1a822 (diff) | |
parent | 44f2f9aa536d8cced21f4e9c58f7d9d98bd88a71 (diff) |
Merge pull request #1122 from svart-riddare/issue-1108
Suggestion for issue #1108
-rw-r--r-- | include/rapidjson/pointer.h | 7 | ||||
-rw-r--r-- | test/unittest/pointertest.cpp | 9 |
2 files changed, 13 insertions, 3 deletions
diff --git a/include/rapidjson/pointer.h b/include/rapidjson/pointer.h index 0f377efe..217e71ce 100644 --- a/include/rapidjson/pointer.h +++ b/include/rapidjson/pointer.h @@ -165,7 +165,12 @@ public: GenericPointer(const Token* tokens, size_t tokenCount) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(const_cast<Token*>(tokens)), tokenCount_(tokenCount), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {} //! Copy constructor. - GenericPointer(const GenericPointer& rhs, Allocator* allocator = 0) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) { + GenericPointer(const GenericPointer& rhs) : allocator_(rhs.allocator_), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) { + *this = rhs; + } + + //! Copy constructor. + GenericPointer(const GenericPointer& rhs, Allocator* allocator) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) { *this = rhs; } diff --git a/test/unittest/pointertest.cpp b/test/unittest/pointertest.cpp index d5a688db..855d822c 100644 --- a/test/unittest/pointertest.cpp +++ b/test/unittest/pointertest.cpp @@ -462,7 +462,8 @@ TEST(Pointer, ConstructorWithToken) { TEST(Pointer, CopyConstructor) { { - Pointer p("/foo/0"); + CrtAllocator allocator; + Pointer p("/foo/0", &allocator); Pointer q(p); EXPECT_TRUE(q.IsValid()); EXPECT_EQ(2u, q.GetTokenCount()); @@ -471,6 +472,7 @@ TEST(Pointer, CopyConstructor) { EXPECT_EQ(1u, q.GetTokens()[1].length); EXPECT_STREQ("0", q.GetTokens()[1].name); EXPECT_EQ(0u, q.GetTokens()[1].index); + EXPECT_EQ(&p.GetAllocator(), &q.GetAllocator()); } // Static tokens @@ -489,7 +491,8 @@ TEST(Pointer, CopyConstructor) { TEST(Pointer, Assignment) { { - Pointer p("/foo/0"); + CrtAllocator allocator; + Pointer p("/foo/0", &allocator); Pointer q; q = p; EXPECT_TRUE(q.IsValid()); @@ -499,6 +502,7 @@ TEST(Pointer, Assignment) { EXPECT_EQ(1u, q.GetTokens()[1].length); EXPECT_STREQ("0", q.GetTokens()[1].name); EXPECT_EQ(0u, q.GetTokens()[1].index); + EXPECT_NE(&p.GetAllocator(), &q.GetAllocator()); q = q; EXPECT_TRUE(q.IsValid()); EXPECT_EQ(2u, q.GetTokenCount()); @@ -507,6 +511,7 @@ TEST(Pointer, Assignment) { EXPECT_EQ(1u, q.GetTokens()[1].length); EXPECT_STREQ("0", q.GetTokens()[1].name); EXPECT_EQ(0u, q.GetTokens()[1].index); + EXPECT_NE(&p.GetAllocator(), &q.GetAllocator()); } // Static tokens |