Skip to content

Avoid static destructors during program exit - #1471

Open
jwnimmer-tri wants to merge 1 commit into
jbeder:masterfrom
jwnimmer-tri:never_destroyed
Open

Avoid static destructors during program exit#1471
jwnimmer-tri wants to merge 1 commit into
jbeder:masterfrom
jwnimmer-tri:never_destroyed

Conversation

@jwnimmer-tri

@jwnimmer-tri jwnimmer-tri commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Function-local static variables must either be marked constexpr or never_destroyed. Otherwise, their order of destruction during program exit is indeterminate and can lead to undefined behavior.

https://en.cppreference.com/cpp/language/siof
https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables

Function-local static variables must either be marked constexpr or
never_destroyed. Otherwise, their order of destruction during program
exit is indeterminate and can lead to undefined behavior.

@SGSSGene SGSSGene left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this PR needs some discussion.

What I understand is:
The extra never_destroyed template makes the data types "leak" their data on the heap by not calling delete and by this avoid wrong destruction order.

I think this is quiet some source code overhead. It avoid a theoretical issue that does not occur during execution and it will (hopefully) trigger memory leak detection (address sanitizer or valgrind).

So I am positioning myself against this PR.

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