title: Order of static destructors
body: <p>If a class <code>Foo</code> has a static member variable <code>Bar</code>, I would expect <code>Bar</code>'s destructor to run only after the last instance of <code>Foo</code>'s destructor runs. This doesn't happen with the code snippet below (gcc 6.3, clang 3.8):</p>
  
  <pre><code>#include &lt;memory&gt;
  #include &lt;iostream&gt;
  
  class Foo;
  static std::unique_ptr&lt;Foo&gt; foo;
  
  struct Bar {
      Bar() {
          std::cout &lt;&lt; "Bar()" &lt;&lt; std::endl;
      }
  
      ~Bar() {
          std::cout &lt;&lt; "~Bar()" &lt;&lt; std::endl;
      }
  };
  
  struct Foo {
      Foo() {
          std::cout &lt;&lt; "Foo()" &lt;&lt; std::endl;
      }
  
      ~Foo() {
          std::cout &lt;&lt; "~Foo()" &lt;&lt; std::endl;
      }
  
      static Bar bar;
  };
  Bar Foo::bar;
  
  int main(int argc, char **argv) {
      foo = std::make_unique&lt;Foo&gt;();
  }
  </code></pre>
  
  <p>Outputs:</p>
  
  <pre><code>Bar()
  Foo()
  ~Bar()
  ~Foo()
  </code></pre>
  
  <p>Why is the order of destruction not the reverse of construction here?
  If <code>~Foo()</code> uses <code>Foo::bar</code> this is a use after delete.</p>