Open
Description
Clang rejects following code while gcc compiles it.
https://godbolt.org/z/E3TcTq1hx
struct bar {
int x;
};
consteval int foo() {
const auto [a] = bar{};
return [=] {
return a;
}();
}
int main() {
return foo();
}
Error message from clang:
<source>:14:12: error: call to consteval function 'foo' is not a constant expression
14 | return foo();
| ^
<source>:9:16: note: read of non-constexpr variable '[a]' is not allowed in a constant expression
9 | return a;
| ^
<source>:8:12: note: in call to '[=] {
return a;
}.operator()()'
8 | return [=] {
| ^~~~~
9 | return a;
| ~~~~~~~~~
10 | }();
| ~~~
<source>:14:12: note: in call to 'foo()'
14 | return foo();
| ^~~~~
<source>:6:16: note: declared here
6 | const auto [a] = bar{};
| ^
1 error generated.