title: Stack allocator access violation when enabling MSVC debug iterator
body: <p>I've made a simple stack allocator that can be used to allocate small containers on the stack.
  I've been using this class for a while and it has been working fine.
  However, today I switched debug iterators back on (<code>_ITERATOR_DEBUG_LEVEL=2</code>), and I am suddenly getting access violations in the debugging code that was activated by this switch.</p>
  
  <p>The mix of template programming and standard library coding conventions is making this very hard to debug, and I'm not exactly an expert on allocators either. Am I violating some sort of rule for allocators?</p>
  
  <p>The code below should be able to reproduce the error.</p>
  
  <pre><code>#include &lt;memory&gt;
  #include &lt;vector&gt;
  
  template &lt;typename T, size_t N, template &lt;typename&gt; typename Allocator = std::allocator&gt;
  class StackAllocator : public Allocator&lt;T&gt;
  {
      public:
      using base         = Allocator&lt;T&gt;;
      using pointer_type = typename base::pointer;
      using size_type    = typename base::size_type;
  
      StackAllocator() noexcept = default;
      StackAllocator(const StackAllocator&amp; a_StackAllocator) noexcept = default;
  
      template &lt;typename U&gt;
      StackAllocator(const StackAllocator&lt;U, N, Allocator&gt;&amp; a_StackAllocator) noexcept
      {
      }
  
      pointer_type allocate(size_type a_Size, void* a_Hint = nullptr)
      {
          if (!m_Active &amp;&amp; a_Size &lt;= N)
          {
              m_Active = true;
              return GetStackPointer();
          }
          else
          {
              return base::allocate(a_Size, a_Hint);
          }
      }
  
      void deallocate(pointer_type a_Pointer, size_type a_Size)
      {
          if (a_Pointer == GetStackPointer())
          {
              m_Active = false;
          }
          else
          {
              base::deallocate(a_Pointer, a_Size);
          }
      }
  
      template &lt;class U&gt;
      struct rebind
      {
          using other = StackAllocator&lt;U, N, Allocator&gt;;
      };
  
      private:
      pointer_type GetStackPointer()
      {
          return reinterpret_cast&lt;pointer_type&gt;(m_Data);
      }
  
      std::aligned_storage_t&lt;sizeof(T), alignof(T)&gt; m_Data[N];
      bool m_Active = false;
  };
  
  template &lt;typename T, size_t N&gt;
  class StackVector : public std::vector&lt;T, StackAllocator&lt;T, N&gt;&gt;
  {
      public:
      using allocator_type = StackAllocator&lt;T, N&gt;;
      using base           = std::vector&lt;T, allocator_type&gt;;
  
      StackVector() noexcept(noexcept(allocator_type())):
          StackVector(allocator_type())
      {
      }
  
      explicit StackVector(const allocator_type&amp; a_Allocator) noexcept(noexcept(base(a_Allocator))):
          base(a_Allocator)
      {
          base::reserve(N);
      }
  
      using base::vector;
  };
  
  int main(int argc, char* argv[])
  {
      StackVector&lt;size_t, 1&gt; v;
  
      return v.capacity();
  }
  </code></pre>
  
  <p>I am using MSVC 2017 (15.4.0).</p>