title: Manual poisoning of std::vector
body: <p>In the following code snippet there is an error that is not trivial but I would have expected tools like AddressSanitizer to catch it.</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;iostream&gt;
  
  int main ()
  {
   std::vector&lt;int&gt; toto;
   toto.push_back(2);
   int const&amp; titi = toto[0];
   toto.pop_back();
   std::cout &lt;&lt; titi &lt;&lt; std::endl;
   return 1;
  }
  </code></pre>
  
  <p>When scopping the vector and printing outside of the scope the catch reference an error is thrown use-heap-after-free.</p>
  
  <p>But when there is no scope, the <code>std::vector</code> implementation will probably not release the memory after the pop_back thus the reference is still pointing towards <em>valid</em> memory.</p>
  
  <p>I have search around and I found that you can manually poison memory and I was wondering if this has been implemented  in STL (<a href="https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning" rel="nofollow noreferrer">https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning</a>)</p>