0

In this passage on program exit from cppreference.com

If the completion of the constructor or dynamic initialization for thread-local or static object A was sequenced-before thread-local or static object B, the completion of the destruction of B is sequenced-before the start of the destruction of A

what is the meaning of "sequenced-before"?

In particular, for this program

struct Object {
  Object() {
  }
  ~Object() {
  }
};

Object a;

void f() {
  static Object b;
}

int main() {
  f();
}

is it safe to assume that a.~Object() is called after b.~Object() because a.Object() is called before b.Object()?

John McFarlane
  • 5,528
  • 4
  • 34
  • 38
  • 1
    see also [this answer regarding sequenced-before relations](http://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points/4183735#4183735) (and also the sequence *points* of yesteryear) – jaggedSpire Jan 19 '17 at 19:49

1 Answers1

0

what is the meaning of "sequenced-before"?

Objects are initialized at run time by the run time environment in a sequence. If initialization of one object comes before initialization of a second object, then the construction of the first object is "sequenced-before" construction of the second object.

is it safe to assume that a.~Object() is called after b.~Object() because a.Object() is called before b.Object()?

If you can assume that a.Object() is called before b.Object(), then you can assume that a.~Object() is called after b.~Object(). However, that is not always the case. In your posted code that is true. But it is possible, in a more complex application, that f() is called before a is initialized.

R Sahu
  • 204,454
  • 14
  • 159
  • 270