Skip to content

Commit 7354da8

Browse files
authored
Merge pull request open-source-parsers#640 from cfyzium/master
Fix non-rvalue Json::Value assignment operator (should copy, not move)
2 parents 9a048e5 + 6a15ca6 commit 7354da8

File tree

2 files changed

+2
-13
lines changed

2 files changed

+2
-13
lines changed

include/json/value.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,7 @@ Json::Value obj_value(Json::objectValue); // {}
327327

328328
/// Deep copy, then swap(other).
329329
/// \note Over-write existing comments. To preserve comments, use #swapPayload().
330-
Value& operator=(const Value& other);
331-
#if JSON_HAS_RVALUE_REFERENCES
332-
Value& operator=(Value&& other);
333-
#endif
330+
Value& operator=(Value other);
334331

335332
/// Swap everything.
336333
void swap(Value& other);

src/lib_json/json_value.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -518,18 +518,10 @@ Value::~Value() {
518518
value_.uint_ = 0;
519519
}
520520

521-
Value& Value::operator=(const Value& other) {
522-
swap(const_cast<Value&>(other));
523-
return *this;
524-
}
525-
526-
#if JSON_HAS_RVALUE_REFERENCES
527-
Value& Value::operator=(Value&& other) {
528-
initBasic(nullValue);
521+
Value& Value::operator=(Value other) {
529522
swap(other);
530523
return *this;
531524
}
532-
#endif
533525

534526
void Value::swapPayload(Value& other) {
535527
ValueType temp = type_;

0 commit comments

Comments
 (0)