title: Is a Union Member's Destructor Called
body: <p>C++11 allowed the use of standard layout types in a <code>union</code>: <a href="https://stackoverflow.com/q/40088319/2642059">Member of Union has User-Defined Constructor</a></p>
  
  <p>My question then is: Am I guaranteed the custom destructor will be called, when the <code>union</code> goes out of scope?</p>
  
  <p>My understanding is that we must manually destroy and construct when switching: <a href="http://en.cppreference.com/w/cpp/language/union#Explanation" rel="noreferrer">http://en.cppreference.com/w/cpp/language/union#Explanation</a></p>
  
  <p>But what about an example like this:</p>
  
  <pre><code>{
      union S { string str;
                vector&lt;int&gt; vec;
                ~S() {} } s = { "Hello, world"s };
  }
  </code></pre>
  
  <p>When <code>s</code> goes out of scope, have I leaked the memory the string allocated on the heap because I did not call <code>string</code>'s destructor?</p>