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

Make structs and unions adhere to C++ standard #101

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

gostefan
Copy link
Contributor

@gostefan gostefan commented Sep 3, 2024

Some structs and unions currently don't adhere to the C++ standard.
They rely solely on the compiler implementation doing what we expect it to do.

This PR fixes the elements that don't adhere to the C++ standard.

Only the last to commits are actually part of this PR. All the others are from PR #99 but not basing this PR on that one would lead to conflicts when merging.

@gostefan gostefan force-pushed the fixUnion branch 2 times, most recently from 1c2291b to 6e31208 Compare September 4, 2024 21:31
@gostefan
Copy link
Contributor Author

gostefan commented Sep 4, 2024

Force-update because of the fix to PR #99. The last two commits have the same contents.

@gostefan
Copy link
Contributor Author

gostefan commented Sep 5, 2024

Fixed another issue in PR #99 and needed to force-push. The last two commits still contain the same changes.

The setup before this commit violates the C++ standard.
If two classes with non-standard constructors and/or
destructors are in a union their constructors and/or
destructors have to be called explicitly when
switching between the value types.

Using a union is also unsafe as it's illegal to
access the "wrong" of the two members. But the API
doesn't have a way to tell which member is the active.

The new solution doesn't use unions but allows clients
to safely access even the wrong value.
Accessing non-active members in unions is undefined
behavior. Additionally the C++ Standard doesn't
support anonymous structs. [1]
This puts the current implementation of TVec3 and
TVec4 square into undefined behavior territory.

Removing the unions and anonymous structs is easy
and fixes all problematic paths.

[1]: https://stackoverflow.com/questions/2253878/why-does-c-disallow-anonymous-structs
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.

1 participant