Skip to content

Move semantic for GetObject changed #1994

@tirolerstefan

Description

@tirolerstefan

I have tested latest master commit e4bde97 against release 1.1.0 commit f54b0e4.
It looks like GetObject with assignment doesn't move, but copy data, now.

Here is my minimal code snippet:

#include <iostream>
#include <string>

#include "rapidjson/document.h"
#include "rapidjson/rapidjson.h"


int main (void)
{
    std::string strJson = "{"
                           "\"name\": \"Chuck Norris\","
                           "\"bestfriend\": "
                              "{"
                                  "\"name\": \"Jean Claude\""
                              "}"
                       "}";
    
    rapidjson::Document d;
    rapidjson::ParseResult res = d.Parse(strJson.data());
    
    if (d.HasMember("bestfriend") && d["bestfriend"].IsObject())
        {
        // move semantic !! d["bestfriend"] will become null in v1.1.0.
        const rapidjson::Value& bestfriend  = d["bestfriend"].GetObject();
        
        std::cout << "ObjectEmpty? " << (d["bestfriend"].ObjectEmpty()?"yes":"no") << std::endl;
        }

    return 0;
}

Build line
g++ -g -std=c++11 -o rj -I../rapidjson_repo/include main.cpp

Output with commit f54b0e4 (v1.1.0):
ObjectEmpty? yes

Output with commit e4bde97:
ObjectEmpty? no

Using git bisect, I got commit cbf62de as first "bad" commit:

cbf62de55d684b70df2ae072097568719454f321 is the first bad commit
commit cbf62de55d684b70df2ae072097568719454f321
Author: Krystian Chmura <krystian.chmura@gmail.com>
Date:   Tue Jan 5 14:20:57 2021 +0100

    Add implicit conversion from Object and Array to Value (#1404)
    
    Allows resolution of JSON Pointer on Object and Array

 include/rapidjson/document.h  |  2 ++
 test/unittest/pointertest.cpp | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

Was this change in behaviour intended?
Thanks for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions