Repository navigation
Make NoDestructor's destructor trivial - #267
Merged
Merged
Conversation
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>
derobins
requested review from
akolliasAMD,
gaoikawa,
jordan-turbofish,
kurtmcmillan,
riley-dixon,
sbates130272 and
zbyrne
as code owners
October 19, 2026 17:53
Contributor
There was a problem hiding this comment.
🟢 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
Contributor
Security scan found no critical or high findings on lines changed by this pull requestView 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.