title: Why is COW std::string optimization still enabled in GCC 5.1?
body: <p>According to GCC 5 release changes page (<a href="https://gcc.gnu.org/gcc-5/changes.html" rel="noreferrer">https://gcc.gnu.org/gcc-5/changes.html</a>):</p>
  
  <blockquote>
    <p>A new implementation of std::string is enabled by default, using the small string optimization instead of copy-on-write reference counting</p>
  </blockquote>
  
  <p>I decided to check it and wrote a simple program:</p>
  
  <pre><code>int main()
  {
      std::string x{"blah"};
      std::string y = x;
      printf("0x%X\n", x.c_str());
      printf("0x%X\n", y.c_str());
      x[0] = 'c';
      printf("0x%X\n", x.c_str());
      printf("0x%X\n", y.c_str());
  }
  </code></pre>
  
  <p>And the result is:</p>
  
  <pre><code>0x162FC38
  0x162FC38
  0x162FC68
  0x162FC38
  </code></pre>
  
  <p>Notice that the x.c_str() pointer changes after x[0] = 'c'. This means that the internal buffer is copied upon write. So it seems that COW is still in work. Why?</p>
  
  <p>I use g++ 5.1.0 on Ubuntu.</p>