[Bug c++/102272] New: rejects-valid: VLA captured in generic lambda
simon.giesecke at snowflake dot com
gcc-bugzilla@gcc.gnu.org
Fri Sep 10 08:31:49 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102272
Bug ID: 102272
Summary: rejects-valid: VLA captured in generic lambda
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: simon.giesecke at snowflake dot com
Target Milestone: ---
gcc rejects the following code:
```
int bar();
void foo() {
char data[bar()];
[&](auto *ptr) { data; };
}
```
saying:
```
<source>: In function 'void foo()':
<source>:6:3: error: use of deleted function
'foo()::<lambda(auto:1*)>::~<lambda>()'
6 | [&](auto *ptr) { data; };
| ^~~~~~~~~~~~~~~~~~~~~~~~
<source>:6:5: note: 'foo()::<lambda(auto:1*)>::~<lambda>()' is implicitly
deleted because the default definition would be ill-formed:
6 | [&](auto *ptr) { data; };
| ^
```
This happens in trunk and in various versions back to 8.x I tried.
With a non-generic lambda, this works.
Interestingly, it also works if the length of the VLA doesn't depend on the
result of a function call, but on a parameter of the function.
While this isn't standard C++, gcc supports VLA in C++ code generally, so I
think this should also work.
More information about the Gcc-bugs
mailing list