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

Fix break strict aliasing #3

Merged
merged 1 commit into from
Mar 10, 2022
Merged

Fix break strict aliasing #3

merged 1 commit into from
Mar 10, 2022

Conversation

phprus
Copy link
Contributor

@phprus phprus commented Mar 10, 2022

Fix for issue: #2

@phprus phprus mentioned this pull request Mar 10, 2022
@greg7mdp
Copy link
Owner

Thanks for the PR, Vladislav. However, I don't think it changes what actually is done, and does an extra copy, so I'm reluctant to merge this if the only reason is to appease the compiler. Please let me know if I'm misunderstanding

@phprus
Copy link
Contributor Author

phprus commented Mar 10, 2022

This is std::bit_cast() analog (GCC-11+, Clang-14+, MSVC 19.27+).

Without memcpy the compiler can remove read from val. See https://en.cppreference.com/w/cpp/language/reinterpret_cast#Type_aliasing

There will be no copying:
https://godbolt.org/z/7cheKbbTr

@greg7mdp
Copy link
Owner

Fantastic! I learned something today! thanks!

@greg7mdp greg7mdp merged commit b372a12 into greg7mdp:main Mar 10, 2022
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

Successfully merging this pull request may close these issues.

None yet

2 participants