Skip to content

Fix non-rvalue Json::Value assignment operator (should copy, not move) #640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions include/json/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,7 @@ Json::Value obj_value(Json::objectValue); // {}

/// Deep copy, then swap(other).
/// \note Over-write existing comments. To preserve comments, use #swapPayload().
Value& operator=(const Value& other);
#if JSON_HAS_RVALUE_REFERENCES
Value& operator=(Value&& other);
#endif
Value& operator=(Value other);

/// Swap everything.
void swap(Value& other);
Expand Down
10 changes: 1 addition & 9 deletions src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,18 +518,10 @@ Value::~Value() {
value_.uint_ = 0;
}

Value& Value::operator=(const Value& other) {
swap(const_cast<Value&>(other));
return *this;
}

#if JSON_HAS_RVALUE_REFERENCES
Value& Value::operator=(Value&& other) {
initBasic(nullValue);
Value& Value::operator=(Value other) {
swap(other);
return *this;
}
#endif

void Value::swapPayload(Value& other) {
ValueType temp = type_;
Expand Down