Skip to content

Make NoDestructor's destructor trivial - #267

Merged
derobins merged 1 commit into
developfrom
derobins/no_destructor
Oct 19, 2026
Merged

derobins merged 1 commit into
developfrom
derobins/no_destructor

Conversation

@derobins

Copy link
Copy Markdown
Collaborator

NoDestructor builds its value with placement new in an aligned byte array and keeps the pointer that new returns, rather than holding the value in a union. Its destructor is now trivial, so Clang's -Wexit-time-destructors doesn't warn about the static NoDestructors in src/state.cpp, and their suppressions are removed. Using the pointer from new avoids the reinterpret_cast and std::launder that getting it back from the array would need, and removing the union removes its NOLINT for cppcoreguidelines-pro-type-union-access.

NoDestructor builds its value with placement new in an aligned byte
array and keeps the pointer that new returns, rather than holding the
value in a union. Its destructor is now trivial, so Clang's
-Wexit-time-destructors doesn't warn about the static NoDestructors in
src/state.cpp, and their suppressions are removed. Using the pointer
from new avoids the reinterpret_cast and std::launder that getting it
back from the array would need, and removing the union removes its
NOLINT for cppcoreguidelines-pro-type-union-access.

Co-Authored-By: Claude <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused refactor preserves initialization and lifetime behavior, with no blocking issues identified.

No open issues 🎉

What changed in this PR

Makes NoDestructor trivially destructible while preserving its intentionally undestroyed values.

Changes:

  • Replaces union storage with an aligned byte array and retains the placement-new pointer.
  • Removes obsolete union-access and exit-time-destructor suppressions.
File Description
src/​state.cpp Removes unnecessary warning suppressions and updates comments.
src/​common/​no-destructor.h Uses aligned byte storage and a defaulted trivial destructor.

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor
Security scan found no critical or high findings on lines changed by this pull request

View the security scan run for complete reports.

“New” means the finding is located in a changed file on an added or modified line; it is not a base-versus-head findings delta.

@derobins
derobins merged commit a6ab686 into develop Oct 19, 2026
40 checks passed
@derobins
derobins deleted the derobins/no_destructor branch October 19, 2026 18:06
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.

2 participants