Skip to content

feat: constexpr support with trivial unions - #155

Draft
ChronoInferna wants to merge 2 commits into
bemanproject:mainfrom
ChronoInferna:trivial-unions
Draft

ChronoInferna wants to merge 2 commits into
bemanproject:mainfrom
ChronoInferna:trivial-unions

Conversation

@ChronoInferna

@ChronoInferna ChronoInferna commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Close #36 by implementing p3726 and p3074.

As of today, I don't think Clang has actually merged in support for those two papers, so I would appreciate some help verifying if these are valid changes or not as I can't test the new code (currently macro'd out) until that happens.

More specifically, I don't know which Clang version will actually release with trivial unions and as such might require changing the version in config.hpp. I also don't know what the API for std::start_lifetime actually is, as it's in p3726 but the standard library only has std::start_lifetime_as.

Otherwise here are the changes:

  • Added detection of trivial union support via the __cpp_trivial_union macro and defined the BEMAN_INPLACE_VECTOR_HAS_TRIVIAL_UNION macro in config.hpp.
  • Updated the satisfy_constexpr concept to always be true when trivial unions are supported, allowing more constexpr usage.
  • Introduced union_storage struct for non-trivial types when trivial unions are available, enabling union-based storage and appropriate lifetime management.
  • Modified the storage_for type alias to select union_storage when trivial unions are supported, otherwise falling back to the previous logic.
  • Ensured that the old raw_byte_based_storage is only used when trivial unions are not available.
  • Added appropriate tests

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 98.649%. remained the same — ChronoInferna:trivial-unions into bemanproject:main

@ednolan

ednolan commented Oct 7, 2026

Copy link
Copy Markdown
Member

Tip: If these features exist in Clang trunk, you could add Clang trunk to the CI by specifying:

          "clang": [
            { "versions": ["trunk"],

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.

Alternative implementation using P3074 when compiler support is available

3 participants