title: Is std::cout guaranteed to be initialized before all objects with static storage duration in all translation units?
body: <p>Similar to <a href="https://stackoverflow.com/questions/8784892/is-stdcout-guaranteed-to-be-initialized">this question</a>, but now I have two translation units:</p>
  <pre class="lang-cpp prettyprint-override"><code>// a.cpp
  #include &lt;iostream&gt;
  void print_hello() {
      std::cout &lt;&lt; &quot;hello\n&quot;;
  }
  </code></pre>
  <pre class="lang-cpp prettyprint-override"><code>// b.cpp
  void print_hello();
  struct StaticObject {
      StaticObject() {
          print_hello();
      }
  } static_object;
  int main() {
  }
  </code></pre>
  <p>If I compile these two locally with <code>g++ -std=c++17 a.cpp b.cpp</code>, the resulting <code>a.exe</code> crashes. My compiler version is <code>g++ (Rev2, Built by MSYS2 project) 10.3.0</code> on Windows.
  I am also able to reproduce this behavior by compiling <code>g++ -std=c++17 b.cpp a.cpp</code> with <code>g++-10 (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0</code></p>
  <p>I believe it is because <code>b.cpp</code> does not include <code>&lt;iostream&gt;</code> and <code>static_object</code> gets constructed before anything in <code>a.cpp</code>, corresponding <code>std::ios_base::Init</code> provided by <code>&lt;iostream&gt;</code> in particular. Hence, when <code>print_hello()</code> is called, <code>std::cout</code> is not initialized yet, hence the crash.</p>
  <p>The final question being: is it guaranteed by C++17 that <code>std::cout</code> is initialized before all &quot;user-provided&quot; (for the lack of better word) objects with static storage duration are initialized? Experiments suggest that it is not.</p>