<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58173>58173</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Block expressions accept default arguments, but those default arguments can never be used; no diagnostic issued
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          tahonermann
      </td>
    </tr>
</table>

<pre>
    Block expressions are currently allowed to define default arguments. Unlike C++ lambda expressions, the closure type created for a block expression is immediately type erased. This makes it impossible for any defined default arguments to ever be used; even in an immediately invoked block expression. For example, using Clang 15 (https://godbolt.org/z/zrKfovKMj):
```
$ cat t.cpp
void f() {
  ^(int i = 1) { return i; }();
  auto bp = ^(int i = 2) { return i; };
  bp();
}

$ clang -c -fblocks t.cpp
t.cpp:2:30: error: too few arguments to block call, expected 1, have 0
  ^(int i = 1) { return i; }();
  ~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
t.cpp:4:6: error: too few arguments to block call, expected 1, have 0
  bp();
  ~~ ^
2 errors generated.
```

The behavior illustrated above may be confusing, particularly for someone used to working with C++ lambda expressions; the code looks like it should "work".

Rather than silently accepting default arguments in block expressions, I think it would be best to diagnose them; preferably as an error, potentially one that can be reduced to a warning if there are backward compatibility concerns.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVctu2zoQ_RppQ0SQJcuOF1rk0QBF0c1F-wEkNbJYU6RAUnZ9v76HVNIkdttNC-hBipwzZ85wRsJ25_ZeW3lg9H1y5L2yxjPuiMnZOTJBnxnX2p6oY8GyjnplKL74rAP27ecRm3zBvhqtDsQesuoeF9N8FB1_C5pVDywMwNXWz8AP5wkTRzwAureOcSYuiDDlmRpH6hQ2gUgyIcc9dQX7MmB15AfCnoBtk4WN0LRgmfMz1-6abAyEjuSYIDYDK6vv4xzuDAzfeVTmaA_AuGR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