title: Significance of trivial destruction
body: <p>In C++17, the new <code>std::optional</code> mandates that it be trivially destructible if <code>T</code> is trivially destructible in [optional.object.dtor]:</p>
  
  <blockquote>
    <p><code>~optional();</code><br>
    1 <em>Effects</em>: If <code>is_trivially_destructible_v&lt;T&gt; != true</code> and <code>*this</code> contains a value, calls <code>val-&gt;T::~T()</code>.<br>
    2 <em>Remarks</em>: If <code>is_trivially_destructible_v&lt;T&gt; == true</code> then this destructor shall be a trivial destructor.</p>
  </blockquote>
  
  <p>So this potential implementation fragment would be non-conforming to the standard:</p>
  
  <pre><code>template &lt;class T&gt;
  struct wrong_optional {
      union { T value; };
      bool on;
  
      ~wrong_optional() { if (on) { value.~T(); } }
  };
  </code></pre>
  
  <p>My question is: what is the advantage of this mandate? Presumably, for trivially destructible types, the compiler can figure out that <code>value.~T()</code> is a no-op and emit no code for <code>wrong_optional&lt;T&gt;::~wrong_optional()</code>. </p>