title: Why Clang does not optimize returning of std::string by empty "" constant?
body: <pre><code>#include &lt;string&gt;
  
  std::string foo1()
  {
      return "";
  }
  
  std::string foo2()
  {
      return {};
  }
  
  int main()
  {
      const std::string&amp; test1 = foo1();
      const std::string&amp; test2 = foo2();
  
      return 0;
  }
  </code></pre>
  
  <p><a href="https://godbolt.org/g/ifgNbl" rel="nofollow">https://godbolt.org/g/ifgNbl</a></p>
  
  <p>Clang 3.8 with <code>-O3</code> made this:</p>
  
  <pre><code>foo1():                               # @foo1()
          push    rbx
          sub     rsp, 16
          mov     rbx, rdi
          lea     rdx, [rsp + 8]
          mov     esi, .L.str
          call    std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::basic_string(char const*, std::allocator&lt;char&gt; const&amp;)
          mov     rax, rbx
          add     rsp, 16
          pop     rbx
          ret
  
  foo2():                               # @foo2()
          mov     qword ptr [rdi], std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::_Rep::_S_empty_rep_storage+24
          mov     rax, rdi
          ret
  </code></pre>
  
  <p>But GCC made this (i.e. the same code):</p>
  
  <pre><code>foo1[abi:cxx11]():
          lea     rdx, [rdi+16]
          mov     rax, rdi
          mov     QWORD PTR [rdi+8], 0
          mov     BYTE PTR [rdi+16], 0
          mov     QWORD PTR [rdi], rdx
          ret
  foo2[abi:cxx11]():
          lea     rdx, [rdi+16]
          mov     rax, rdi
          mov     QWORD PTR [rdi+8], 0
          mov     BYTE PTR [rdi+16], 0
          mov     QWORD PTR [rdi], rdx
          ret
  </code></pre>
  
  <p>Why Clang even in the last version does not optimize return of <code>""</code>? Is there any reason for this in the standard, or they forgot about it?</p>