Bug Report
#include <iostream>
#include "nlohmann/json.hpp"
using namespace std;
using json = nlohmann::json;
class State {
public:
double x;
~State() {
cout << "destroyed" << endl;
}
};
void from_json(const json& j, State& p) {
try {
p.x = j.at("x").get<double>();
} catch(json::type_error& e) {
std::cerr << e.what() << std::endl;
} catch(json::out_of_range& e) {
std::cerr << e.what() << std::endl;
}
}
int main() {
json data;
State s;
data["x"] = 10.;
s = data;
cout << s.x << endl;
return 0;
}
Output is:
-
What is the expected behavior?
do not call destructor during assignment
-
And what is the actual behavior instead?
destructor is called
-
Which compiler and operating system are you using? Is it a supported compiler?
g++ (Gentoo 6.4.0-r1 p1.3) 6.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- Did you use a released version of the library or the version from the
develop branch?
checked for both: master and develop branch.
Could you please describe, whether it is a feature or a bug :) By default assignment operator doesn't call destructor, that is why the behavior seems to me unexpected.
Thank you!
Bug Report
What is the issue you have?
Destructor being called in an unexpected place.
Please describe the steps to reproduce the issue. Can you provide a small but working code example?
Output is:
What is the expected behavior?
do not call destructor during assignment
And what is the actual behavior instead?
destructor is called
Which compiler and operating system are you using? Is it a supported compiler?
developbranch?checked for both: master and develop branch.
Could you please describe, whether it is a feature or a bug :) By default assignment operator doesn't call destructor, that is why the behavior seems to me unexpected.
Thank you!