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

Use nested struct to provide constexpr constants #286

Closed
wants to merge 1 commit into from

Conversation

jwnimmer-tri
Copy link
Contributor

🦟 Bug fix

A portion of #269.

Summary

Use constexpr for simple static constants, to avoid the C++ global static construction and destruction order fiascos.

This is an alternative approach vs #283. Due to MSVC's apparent limitiations, the only way to provide inline static constants is via a helper struct (or namespace-scoped globals), so that the class Color exists as a complete type prior to declaring constants that use it.

Deprecate the const-only (non-constexpr) spelling of the constants.

At the moment, only Color has been refactored with this pattern while we discuss the implications.

In this version of the fix, we have an API+ABI break (with a deprecation transition), and thus will require users to refactor their code. In the #283 version of the fix, we remain API compatible (but still break ABI).

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge

Deprecate the non-constexpr spelling of the constants.
@jwnimmer-tri
Copy link
Contributor Author

I'm seeking input from project maintainers on whether this (#286) or else #283 is your preferred tactic to resolve the fiasco problem. Once I have that, I'll close the dispreferred PR, and update the preferred PR to cover all of the relevant types (Vector2, Vector3, etc.) that use the same pattern.

@chapulina chapulina added the bug Something isn't working label Nov 23, 2021
@mjcarroll
Copy link
Contributor

Thanks for taking this on @jwnimmer-tri . I'm taking a look at both approaches and will let you know what I prefer, at least.

@jwnimmer-tri
Copy link
Contributor Author

Closing in lieu of #283.

@jwnimmer-tri jwnimmer-tri deleted the static-constexpr-2 branch December 10, 2021 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants