<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - "lambda expression in default argument cannot capture any entity" is not correct"
   href="https://bugs.llvm.org/show_bug.cgi?id=45032">45032</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>"lambda expression in default argument cannot capture any entity" is not correct
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>arthur.j.odwyer@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>// <a href="https://godbolt.org/z/mWxfE2">https://godbolt.org/z/mWxfE2</a>
void g6(int = ([x=1]{ return x; })());

test.cc:2:16: error: lambda expression in default argument cannot capture any
entity
void g6(int = ([x=1]{ return x; })());
               ^

The declaration of "g6" is taken directly from the example code in
<a href="https://eel.is/c++draft/expr.prim.lambda#capture-9">https://eel.is/c++draft/expr.prim.lambda#capture-9</a>
The text says:
<span class="quote">> Because local entities are not odr-usable within a default argument, a lambda-expression appearing in a default argument cannot implicitly or explicitly capture any local entity. Such a lambda-expression can still have an init-capture if any full-expression in its initializer satisfies the constraints of an expression appearing in a default argument.</span >

Notice: any _local_ entity. GCC, MSVC, and ICC seem to implement the "any local
entity" wording correctly; only Clang rejects code like "g6".

The full test case from the Standard is:

void f2() {
  int i = 1;
  void g1(int = ([i]{ return i; })());          // error
  void g2(int = ([i]{ return 0; })());          // error
  void g3(int = ([=]{ return i; })());          // error
  void g4(int = ([=]{ return 0; })());          // OK
  void g5(int = ([]{ return sizeof i; })());    // OK
  void g6(int = ([x=1]{ return x; })());        // OK (but Clang rejects it)
  void g7(int = ([x=i]{ return x; })());        // error
}</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>