title: Does default constructor zero-initialize member array variable?
body: <p>When I examine following program with it's output, I found quite confusing that to get a FrameA object by return value:  </p>
  
  <ol>
  <li>when <em>a empty ctor is defined, the member array field is remain uninitialized</em>  </li>
  <li><p>when <em>let the compiler generate the ctor, the member array field is initialized to all 0</em>  </p>
  
  <pre><code>auto a = f();       // f() --&gt; return A();
  </code></pre></li>
  </ol>
  
  <p>Given following <a href="http://sscce.org/" rel="nofollow">SSCCE</a></p>
  
  <pre><code>#include &lt;cstring&gt;
  #include &lt;iostream&gt;
  #include &lt;chrono&gt;
  #include &lt;algorithm&gt;
  
  using namespace std;
  
  const int MAX = 9999999;
  
  struct FrameA {
    // FrameA() {}
    // FrameA(const FrameA &amp;v) { memcpy(data, v.data, sizeof(data)); }
    char data[1000];
  };
  
  FrameA f(int i) { return FrameA(); }
  
  int test(int odd) {
    int sum = 0;
    auto begin = chrono::steady_clock::now();
    for (int i = 0; i &lt; MAX; ++i) {
      auto v = f(odd);
      sum += v.data[0] + v.data[330];
    }
    auto end = chrono::steady_clock::now();
    cout &lt;&lt; chrono::duration_cast&lt;chrono::milliseconds&gt;(end - begin).count()
         &lt;&lt; " (milliseconds)" &lt;&lt; endl;
    return sum;
  }
  
  int _tmain(int argc, _TCHAR *argv[]) {
    test(0);
    test(1);
    return 0;
  }
  </code></pre>
  
  <p>When defined an empty ctor, the output is like:</p>
  
  <blockquote>
    <p>g++ v4.8.1</p>
    
    <p>72 (milliseconds)<br>
    73 (milliseconds)  </p>
  </blockquote>
  
  <p>But use compiler generated ctor, the output is:</p>
  
  <blockquote>
    <p>g++ v4.8.1</p>
    
    <p>1401 (milliseconds)<br>
    1403 (milliseconds)  </p>
  </blockquote>
  
  <p>I also tested on VC12, the result is similar.</p>
  
  <p>After examine the assembly, I found when using compiler generated ctor:</p>
  
  <pre><code>  for (int i = 0; i &lt; MAX; ++i) {
      auto v = f(odd);
  00A31701  push        3E8h  
  00A31706  lea         eax,[ebp-3F8h]  
  00A3170C  push        0  
  00A3170E  push        eax  
  00A3170F  call        _memset (0A32460h)               ;; memset FrameA to 0
      sum += v.data[0] + v.data[330];
  00A31714  movsx       eax,byte ptr [ebp-3F8h] 
  </code></pre>
  
  <p>But using an empty ctor won't call <code>memset</code> to set the array in FrameA to zero.</p>
  
  <p>Is there any explanation to this?</p>
  
  <p>BTW, I searched the C++ 11 draft n3242, but Chap 8.5 <code>zero-initialize</code> and <code>default-initialize</code> seems doesn't covered this case. Is there anything I missed?</p>