title: Strange values in a lambda returning initializer_list
body: <p>Consider this <strong>C++11</strong> code snippet:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;set&gt;
  #include &lt;stdexcept&gt;
  #include &lt;initializer_list&gt;
  
  
  int main(int argc, char ** argv)
  {
      enum Switch {
          Switch_1,
          Switch_2,
          Switch_3,
          Switch_XXXX,
      };
  
      int foo_1 = 1;
      int foo_2 = 2;
      int foo_3 = 3;
      int foo_4 = 4;
      int foo_5 = 5;
      int foo_6 = 6;
      int foo_7 = 7;
  
      auto get_foos = [=] (Switch ss) -&gt; std::initializer_list&lt;int&gt; {
          switch (ss) {
              case Switch_1:
                  return {foo_1, foo_2, foo_3};
              case Switch_2:
                  return {foo_4, foo_5};
              case Switch_3:
                  return {foo_6, foo_7};
              default:
                  throw std::logic_error("invalid switch");
          }
      };
  
      std::set&lt;int&gt; foos = get_foos(Switch_1);
      for (auto &amp;&amp; foo : foos) {
          std::cout &lt;&lt; foo &lt;&lt; " ";
      }
      std::cout &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>Whatever compiler I try, all seem to handle it incorrectly. This makes me think that I am doing something wrong rather than it's a common bug across multiple compilers.</p>
  
  <p><strong>clang 3.5</strong> output:</p>
  
  <pre><code>-1078533848 -1078533752 134518134
  </code></pre>
  
  <p><strong>gcc 4.8.2</strong> output:</p>
  
  <pre><code>-1078845996 -1078845984 3
  </code></pre>
  
  <p><strong>gcc 4.8.3</strong> output (compiled on <a href="http://www.tutorialspoint.com" rel="noreferrer">http://www.tutorialspoint.com</a>):</p>
  
  <pre><code>1 2 267998238
  </code></pre>
  
  <p><strong>gcc (unknown version)</strong> output (compiled on <a href="http://coliru.stacked-crooked.com" rel="noreferrer">http://coliru.stacked-crooked.com</a>)</p>
  
  <pre><code>-1785083736 0 6297428 
  </code></pre>
  
  <p>The problem seems to be caused by using <code>std::initializer_list&lt;int&gt;</code> as a return value of lambda. When changing lambda definition to <code>[=] (Switch ss) -&gt; std::set&lt;int&gt; {...}</code> returned values are correct.</p>
  
  <p>Please, help me solve this mystery.</p>