Issue 134897
Summary [clang++] Can not capture member of structured binding to lambda in constant evaluation.
Labels clang
Assignees
Reporter MiroPalmu
    Clang rejects following code while gcc compiles it.

https://godbolt.org/z/E3TcTq1hx

```cpp
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.
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to