Skip to content
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

Move semantic for GetObject changed #1994

Open
tirolerstefan opened this issue Feb 21, 2022 · 1 comment
Open

Move semantic for GetObject changed #1994

tirolerstefan opened this issue Feb 21, 2022 · 1 comment

Comments

@tirolerstefan
Copy link

tirolerstefan commented Feb 21, 2022

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 <[email protected]>
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!

@tirolerstefan
Copy link
Author

tirolerstefan commented Feb 22, 2022

@slsyy - maybe you have an idea, too (referring #1404). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant