Status3543
Status3543

Reputation: 1277

Are there any situations where a class destructor would not be called for a class when the scope ends?

Are there any situations where a class destructor would not be called for a class when it leaves the scope?

Upvotes: 0

Views: 171

Answers (1)

Angelicos Phosphoros
Angelicos Phosphoros

Reputation: 3083

Well, assuming that the object here is plain value (not member of union or allocated in heap so cannot be leaked), I can imagine only one situation: ending a process by something like std::terminate.

It can be called directly or called in situations when uncatched exception occurs in noexcept method.

It may be not "correct" to call this situation an "end of the scope" because you never actually return from std::terminate. However, from practical point of view this is probably exact situation which you want to know about.

Upvotes: 3

Related Questions