Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suspect that this might be compiler-specific behavior. Here's my theory:</p> <p>Because (in this particular case) an implicitly-defined T() is a <em>trivial</em> constructor (as defined in 12.1(5) of the standard), the compiler doesn't even attempt to generate a body for T(). Since there's no ctor body, there are no exceptions that could possibly be generated during "construction" (of which there isn't any, really), so there's no need to generate a dtor call, and so no need to generate a dtor body, only to find out that the base class's dtor is private.</p> <p>But as soon as T() becomes non-trivial (even if it remains implicitly-defined), a ctor body must be generated, and you get the error. Something as simple as adding a member to class T that has a user-defined constructor would make the implicitly-defined T() become non-trivial.</p> <p>A separate, but related, issue is that <code>new T()</code> doesn't generate a dtor call (since you don't have a corresponding <code>delete</code> anywhere). In contrast, if I just replace <code>new T()</code> with <code>T dummy</code> in your code, then I get the following from <code>gcc</code>, suggesting that it's now doing the full check for dtor accessibility (as a consequence of having to generate a dtor call):</p> <pre><code>test.cpp: In destructor 'T::~T()': test.cpp:3: error: 'indestructible_base::~indestructible_base()' is private test.cpp:7: error: within this context test.cpp: In function 'int main()': test.cpp:12: note: synthesized method 'T::~T()' first required here test.cpp:12: warning: unused variable 'dummy' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload