title: Using lambda in default initializer gcc vs clang
body: <pre><code>#include &lt;cassert&gt;
  #include &lt;cmath&gt;
  
  int main()
  {
      struct point_of_cone
      {
          double x, y;
          double z = [&amp;] { using std::sqrt; return sqrt(x * x + y * y); }();
      };
      point_of_cone p = {3.0, 4.0};
      assert(p.z == 5.0);
  }
  </code></pre>
  
  <p>Works fine for <code>clang++</code> from trunk, but for <code>g++</code> from trunk fails with error message (<a href="http://melpon.org/wandbox/permlink/n818z48nMp9OlALf" rel="nofollow noreferrer">link</a>):</p>
  
  <blockquote>
    <p>error: 'this' was not captured for this lambda function</p>
  </blockquote>
  
  <p>Definition of <code>point_of_cone</code> in namespace scope works fine for both.</p>
  
  <p>Slightly modified definition with <code>[this]</code> lambda capture works fine also for both in either global or local scope.</p>
  
  <p>Which compiler is right?</p>