Issue 163498
Summary Worse diagnostic for init-captured lambda appearing within a brace initializer
Labels clang:frontend, clang:diagnostics, lambda
Assignees
Reporter zyn0217
    ```cpp
struct S {
  template <class T>
  S(T) {}
};

void foo() {
  S s([a(42), &] {}); // Clang diagnoses 'capture default must be first' which is very clear
}
```
However, if we initialize S with a brace initializer,

```cpp
struct S {
  template <class T>
  S(T) {}
};

void foo() {
  S s{[a(42), &] {}};
}
```

Clang diagnoses

```
<source>:7:8: error: use of undeclared identifier 'a'
 7 |   S s{[a(42), &] {}};
      |        ^
<source>:7:13: error: expected ']'
    7 |   S s{[a(42), &] {}};
      |             ^
<source>:7:7: note: to match this '['
    7 |   S s{[a(42), &] {}};
      | ^
<source>:7:7: warning: array designators are a C99 extension [-Wc99-designator]
    7 |   S s{[a(42), &] {}};
      | ^~~~~~~~~~
```

for which clang does seem to parse it as an array designator and incurs confusing diagnostics.

See it on godbolt:

https://godbolt.org/z/xq6GfEbcx

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to