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

GCC9 break: trying to memcpy C++ objects #1700

Open
ns-osmolsky opened this issue Apr 24, 2020 · 5 comments
Open

GCC9 break: trying to memcpy C++ objects #1700

ns-osmolsky opened this issue Apr 24, 2020 · 5 comments
Labels

Comments

@ns-osmolsky
Copy link

GCC9 identifies a case of undefined behavior where the code attempts to copy C++ objects with std::memcpy.

rapidjson/include/rapidjson/document.h:1939:24: error: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘class NsJson::GenericValue<NsJson::UTF8<> >’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Werror=class-memaccess]

[2020-04-22T03:02:10.929Z]  1939 |             std::memcpy(e, values, count * sizeof(GenericValue));
[2020-04-22T03:02:10.929Z]       |             ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

rapidjson/include/rapidjson/document.h:540:7: note: ‘class NsJson::GenericValue<NsJson::UTF8<> >’ declared here
[2020-04-22T03:02:10.929Z]   540 | class GenericValue {
[2020-04-22T03:02:10.929Z]       |       ^~~~~~~~~~~~
@miloyip
Copy link
Collaborator

miloyip commented Apr 27, 2020

This is a warning. I suggest adding pragma to ignore this.
Other suggestions are welcome.

@ns-osmolsky
Copy link
Author

I suggest that you fix the broken code by merging #1698.

@jcbollinger
Copy link

It is perilous to ignore or suppress warnings about undefined behavior. Exercising UB is a primary source of misbehavior, and especially for optimization-associated behavior variation. And it is especially an issue for a header-only library such as this one, because it is impossible for the library distribution to provide suitable tests for the observable behavior, as it may vary from use to use.

This issue (which also affects GCC 8) ought to be fixed, not papered over.

@ns-osmolsky
Copy link
Author

@jcbollinger indeed, see #1698.

Hoshpak added a commit to void-linux/void-packages that referenced this issue Oct 27, 2020
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.
Logarithmus pushed a commit to Logarithmus/void-packages that referenced this issue Nov 15, 2020
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.
dniklaus pushed a commit to dniklaus/rapidjson that referenced this issue Feb 21, 2023
@RaoGuangxiang
Copy link

git clone the latest, inteading of downloading in the release url.

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

Successfully merging a pull request may close this issue.

4 participants