| Issue |
58173
|
| Summary |
Block expressions accept default arguments, but those default arguments can never be used; no diagnostic issued
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
tahonermann
|
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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs