title: placement new - buffer's value preserving
body: <p>Is there a way to preserve original value of the buffer passed to placement new? Sample code:</p>
  
  <pre><code>struct MyStruct {
    int number;
    char bytes[100];
  } __attribute__ ((packed));
  
  char data[sizeof(MyStruct)]; // contains value received via TCP
  
  MyStruct* create_struct_a() {
    char tmp[sizeof(MyStruct)];
    memcpy(tmp, data, sizeof(MyStruct));
    MyStruct* result = new (data) MyStruct;
    memcpy(result, tmp, sizeof(MyStruct));
    return result;
  }
  
  MyStruct* create_struct_b() {
    return new (data) MyStruct;
  }
  </code></pre>
  
  <p>gcc 5.3 produces same asm code for both functions when MyStruct::bytes is small:</p>
  
  <pre><code>create_struct_a():
      movl    $data, %eax
      ret
  create_struct_b():
      movl    $data, %eax
      ret
  </code></pre>
  
  <p>but when MyStruct::bytes size is larger than 150 gcc 5.3 produces:</p>
  
  <pre><code>create_struct_a():
      subq    $168, %rsp
      movl    $154, %edx
      movl    $data, %esi
      movq    %rsp, %rdi
      call    memcpy
      movq    %rsp, %rsi
      movl    $154, %edx
      movl    $data, %edi
      call    memcpy
      movl    $data, %eax
      addq    $168, %rsp
      ret
  create_struct_b():
      movl    $data, %eax
      ret
  </code></pre>
  
  <p>I want the smaller asm code without memcpy for the larger structure, but can't find a legal way to force compiler to do this. <code>char data[sizeof(MyStruct)]</code> will be also used for storing other packed types with <code>size &lt;= sizeof(MyStruct)</code> so data type should be <code>char[sizeof(MyStruct)]</code> not <code>MyStruct</code>.</p>