静态对象在块作用域与全局作用域的生命周期结束

End of lifetime of static object at block scope versus global scope

在这段关于程序退出的文章中 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

"sequenced-before"是什么意思?

特别是对于这个程序

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

Object a;

void f() {
  static Object b;
}

int main() {
  f();
}

假设 a.~Object() 之后被调用 b.~Object() 是安全的,因为 a.Object() 之前被调用 b.Object()?

what is the meaning of "sequenced-before"?

对象按顺序在 运行 时间由 运行 时间环境初始化。如果一个对象的初始化发生在第二个对象的初始化之前,那么第一个对象的构造就是第二个对象的"sequenced-before"构造。

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

如果您可以假设 a.Object()b.Object() 之前调用,那么您可以假设 a.~Object()b.~Object() 之后调用。然而,情况并非总是如此。在您发布的代码中是正确的。但在更复杂的应用程序中,可能会在 a 初始化之前调用 f()