novelrt / NovelRT

A cross-platform 2D game engine accompanied by a strong toolset for visual novels.
MIT License
183 stars 43 forks source link

Added mechanism to type pun semi-safe #539

Closed Pheubel closed 1 year ago

Pheubel commented 1 year ago

Please check if the PR fulfills these requirements

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...) This PR aims to solve the type punning issues of https://github.com/novelrt/NovelRT/issues/402. I am not certain if that will be enough to get GCC support up and running.

Is there an open issue that this resolves? If so, please link it here. This PR

What is the current behavior? (You can also link to an open issue here) NovelRT fails to build with GCC.

What is the new behavior (if this is a feature change)? NovelRT no longer fails to build with GCC due to type punning issues.

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?) This should not introduce a breaking change to the API or behavior.

Other information:

this handles most cases, as long as C++ 17 is used and the macros don't cry.

in C++ 20 std::bit_set is used. some compilers support it in earlier C++ versions as a sort of compiler intrinsic, if one is available it might use it. if the compiler has not implemented std::bit_set yet or a built in implementation cannot be found, it will fallback on memcpy for GNU based compilers except clang and icc, these use reinterpret_cast as fallback.

the list of gnu exceptions is a tricky one to pin down and this is my current best attempt.