title: std::vector<std::string> crash
body: <p>This question is continuation of <a href="https://stackoverflow.com/questions/4764048/stl-and-release-debug-library-mess">my question</a>.</p>
  
  <p>Here is problematic code.</p>
  
  <p>a.h:</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;vector&gt;
  
  std::vector&lt;std::string&gt; foo();
  </code></pre>
  
  <p>a.cpp</p>
  
  <pre><code>#include "a.h"
  
  std::vector&lt;std::string&gt; foo()
  {
     std::vector&lt;std::string&gt; v;
     return v;
  }
  </code></pre>
  
  <p>and finally main.cpp:</p>
  
  <pre><code>#include "a.h"
  #include &lt;iostream&gt;
  
  int main()
  {
      std::vector&lt;std::string&gt; s = foo();
  
      return 0;
  }
  </code></pre>
  
  <p>Compilation as following (main.cpp is compiled with STL debugging flag):</p>
  
  <pre><code>g++ -c a.cpp
  g++ -D_GLIBCXX_DEBUG main.cpp a.o
  </code></pre>
  
  <p>When running a.out, process crashes:</p>
  
  <pre><code>Core was generated by `./a.out'.
  Program terminated with signal 11, Segmentation fault.
  #0  0x00007fe355998c43 in __gnu_debug::_Safe_iterator_base::_M_detach_single() () from /usr/lib64/libstdc++.so.6
  (gdb) bt
  #0  0x00007fe355998c43 in __gnu_debug::_Safe_iterator_base::_M_detach_single() () from /usr/lib64/libstdc++.so.6
  #1  0x00007fe355999ebc in __gnu_debug::_Safe_sequence_base::_M_detach_all() () from /usr/lib64/libstdc++.so.6
  #2  0x0000000000400cac in __gnu_debug::_Safe_sequence_base::~_Safe_sequence_base() ()
  #3  0x0000000000400cc6 in __gnu_debug::_Safe_sequence&lt;std::__debug::vector&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::allocator&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;::~_Safe_sequence() ()
  #4  0x0000000000400ce7 in std::__debug::vector&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::allocator&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt;::~vector() ()
  #5  0x0000000000400c35 in main ()
  </code></pre>
  
  <p>My gcc:</p>
  
  <pre><code>Using built-in specs.
  Target: x86_64-suse-linux
  Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.4 --enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --program-suffix=-4.4 --enable-linux-futex --without-system-libunwind --with-arch-32=i586 --with-tune=generic --build=x86_64-suse-linux
  Thread model: posix
  gcc version 4.4.1 [gcc-4_4-branch revision 150839] (SUSE Linux)
  </code></pre>