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
Correct object copying in document.h #1698
Conversation
- this came up when building the code with GCC9 + copying C++ objects with memcpy() is only permitted for Trivial types, the rest should be copied via copy or assignment + tweaked the code to construct the objects in place and then assign Ran "make test", looks OK.
Wow, it looks like the old Visual Studio 2013 does not understand |
|
I am not sure if this change would affect runtime performance. |
OK, I've just pushed a C++03 workaround. As for perf, I ran the tests on my VM and don't see any difference. |
But I think it may have performance overhead, for example, default construction and assignment is non-trivial. Default construction sets type to kNullType, and then assignment needs to first checking the type and deallocate it if needed. |
There is definitely overhead, yet it may be insignificant for the types in play here. Do you have a concrete benchmark that you are concerned with? Or looking at it from the opposite perspective, this change is about correctness. Doing |
|
Please build with GCC9 and it will tell you that the code is incorrect... even if it happens to work in this special case. What you are doing results in undefined behavior as per the ISO C++ Standard. |
As usual, another possibility is to add a new level of indirection and put all members into a trivial local Edit: Ok, this is not as straight-forward as we keep real objects in the array/object buffers. |
Well, yet that would still involve construction for each object (as I am doing already) followed by a memcpy of a member (while I am doing copy assignment of the whole). The net result is looks identical to me. |
Closing the PR as it is just hanging here:
|
the patch intended to fix compilation broke rapidjson as documented in #25912 I verified this by compiling and running the test suite with and without the patch applied. There is a proposed fix in Tencent/rapidjson#1698 which seemingly was rejected by the upstream developers, the issue is documented at Tencent/rapidjson#1700. Since upstream insists that what they are doing is correct, make the compiler ignore the errors for now. Alternatively, we could still apply the proposed patch to our package.
the patch intended to fix compilation broke rapidjson as documented in void-linux#25912 I verified this by compiling and running the test suite with and without the patch applied. There is a proposed fix in Tencent/rapidjson#1698 which seemingly was rejected by the upstream developers, the issue is documented at Tencent/rapidjson#1700. Since upstream insists that what they are doing is correct, make the compiler ignore the errors for now. Alternatively, we could still apply the proposed patch to our package.
the PR is merge error to the latest version, so it is better to keep it open and rebase from time to time |
should be copied via copy or assignment
Ran "make test", looks OK.
Fixes #1700