GCC 9.1 returns void& as result type for an explicit destructor call. Is this a bug? : <p>I'm trying to get <a href="https://stackoverflow.com/a/10722840/4694124">this is-class-defined-check</a> to work, which relies on the fact that <code>decltype(std::declval&lt;Foo&gt;().~Foo())</code> is <code>void</code> if <code>Foo</code> has a destructor (which it has if it is defined…) and is ill-formed otherwise, invoking SFINAE in this case.</p>

<p>However, I can't get the code to work with GCC 9.1, and that is because GCC 9.1 seems to consider that type to be <code>void &amp;</code> <em>if the destructor is defaulted</em>, consider this example:</p>

<pre><code>#include &lt;type_traits&gt;

class Foo {
public:
// With this, the DestructorReturnType below becomes "void"
//    ~Foo () {} 
};

// … unless I specify the user-defined destructor above, in which case it is "void"
using DestructorReturnType = decltype(std::declval&lt;Foo&gt;().~Foo());

template&lt;class T&gt;
class TD;

// Says: aggregate 'TD&lt;void&amp;&gt; t' has incomplete type and cannot be defined
TD&lt;DestructorReturnType&gt; t;
</code></pre>

<p>(available at <a href="https://gcc.godbolt.org/z/K1TjOP" rel="noreferrer">https://gcc.godbolt.org/z/K1TjOP</a> ) </p>

<p>If I user-define an empty destructor, the type jumps back to <code>void</code>. Also if I switch back to GCC 8.x.</p>

<p>The C++17 standard states in [expr.call]:</p>

<blockquote>
  <p>If the postfix-expression designates a destructor, the type of the function call expression is void; […]</p>
</blockquote>

<p>Because of all this, I suspect that GCC 8.x (and clang, …) are correct, and GCC 9.1 is just wrong. Or am I missing something?</p>
