title: gcc4.9.2's libstdc++ implementation of std::vector inherits from _Vector_base (non-virtual destuctor). Why is this OK?
body: <p>So I have been using a container derived from std::vector for some time. Perhaps this is a poor design decision for several reasons, and the question of whether or not you should do such a thing has be discussed extensively here:</p>
  
  <p><a href="https://stackoverflow.com/questions/4353203/thou-shalt-not-inherit-from-stdvector">Thou shalt not inherit from std::vector</a></p>
  
  <p><a href="https://stackoverflow.com/questions/6806173/subclass-inherit-standard-containers">Subclass/inherit standard containers?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/922248/is-there-any-real-risk-to-deriving-from-the-c-stl-containers">Is there any real risk to deriving from the C++ STL containers?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2034916/is-it-okay-to-inherit-implementation-from-stl-containers-rather-than-delegate">Is it okay to inherit implementation from STL containers, rather than delegate?</a></p>
  
  <p>I am sure I have missed some of the discussions…but reasonable arguments for both viewpoints are found in the links. As far as I can tell, the "because ~vector() is non-virtual" is the foundation for the "rule" that you shouldn't inherit from stl containers. However, if I look at the implementation for std::vector in g++ 4.9.2, I find that std::vector inherits from _Vector_base, and _Vector_base a non-virtual destructor.</p>
  
  <pre><code>template&lt;typename _Tp, typename _Alloc = std::allocator&lt;_Tp&gt; &gt;
  class vector : protected _Vector_base&lt;_Tp, _Alloc&gt;
  {
  ...
    ~vector() _GLIBCXX_NOEXCEPT
    { std::_Destroy(this-&gt;_M_impl._M_start, this-&gt;_M_impl._M_finish,
      _M_get_Tp_allocator()); }
  
  ...
  }
  </code></pre>
  
  <p>where:</p>
  
  <pre><code>template&lt;typename _Tp, typename _Alloc&gt;
  struct _Vector_base
  {
  ...
    ~_Vector_base() _GLIBCXX_NOEXCEPT
    { _M_deallocate(this-&gt;_M_impl._M_start, this-&gt;_M_impl._M_end_of_storage
      - this-&gt;_M_impl._M_start); }
  
  ...
  }
  </code></pre>
  
  <p>So the gcc 4.9.2 implementation of std::vector inherits from base classes with a non-virtual destructor. This leads me to believe that it is an acceptable practice. Why is this OK? What are the specific conditions by which such a practice is not dangerous?</p>