<feed xmlns='http://www.w3.org/2005/Atom'>
<title>llvm-project.git/clang/test/Parser/lambda-misplaced-capture-default.cpp, branch main</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.
</subtitle>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/'/>
<entry>
<title>[Clang] fix confusing diagnostics for lambdas with init-captures inside braced initializers (#166180)</title>
<updated>2025-11-06T20:55:36+00:00</updated>
<author>
<name>Oleksandr T.</name>
<email>oleksandr.tarasiuk@outlook.com</email>
</author>
<published>2025-11-06T20:55:36+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=bb6d2bea6495b044a0773598916eba801f8d38fc'/>
<id>bb6d2bea6495b044a0773598916eba801f8d38fc</id>
<content type='text'>
Fixes #163498

---

This PR addresses the issue of confusing diagnostics for lambdas with
init-captures appearing inside braced initializers.

Cases such as:

```cpp
S s{[a(42), &amp;] {}};
```

were misparsed as C99 array designators, producing unrelated
diagnostics, such as `use of undeclared identifier 'a'`, and `expected
']'`

---


https://github.com/llvm/llvm-project/blob/bb9bd5f263226840194b28457ddf9861986db51f/clang/lib/Parse/ParseInit.cpp#L470


https://github.com/llvm/llvm-project/blob/bb9bd5f263226840194b28457ddf9861986db51f/clang/lib/Parse/ParseInit.cpp#L74


https://github.com/llvm/llvm-project/blob/bb9bd5f263226840194b28457ddf9861986db51f/clang/include/clang/Parse/Parser.h#L4652-L4655


https://github.com/llvm/llvm-project/blob/24c22b7de620669aed9da28de323309c44a58244/clang/lib/Parse/ParseExprCXX.cpp#L871-L879

The tentative parser now returns `Incomplete` for partially valid lambda
introducers, preserving the `lambda` interpretation and allowing the
proper diagnostic to be issued later.

---

Clang now correctly recognizes such constructs as malformed lambda
introducers and emits the expected diagnostic — for example,
“capture-default must be first” — consistent with direct initialization
cases such as:

```cpp
S s([a(42), &amp;] {});
```</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Fixes #163498

---

This PR addresses the issue of confusing diagnostics for lambdas with
init-captures appearing inside braced initializers.

Cases such as:

```cpp
S s{[a(42), &amp;] {}};
```

were misparsed as C99 array designators, producing unrelated
diagnostics, such as `use of undeclared identifier 'a'`, and `expected
']'`

---


https://github.com/llvm/llvm-project/blob/bb9bd5f263226840194b28457ddf9861986db51f/clang/lib/Parse/ParseInit.cpp#L470


https://github.com/llvm/llvm-project/blob/bb9bd5f263226840194b28457ddf9861986db51f/clang/lib/Parse/ParseInit.cpp#L74


https://github.com/llvm/llvm-project/blob/bb9bd5f263226840194b28457ddf9861986db51f/clang/include/clang/Parse/Parser.h#L4652-L4655


https://github.com/llvm/llvm-project/blob/24c22b7de620669aed9da28de323309c44a58244/clang/lib/Parse/ParseExprCXX.cpp#L871-L879

The tentative parser now returns `Incomplete` for partially valid lambda
introducers, preserving the `lambda` interpretation and allowing the
proper diagnostic to be issued later.

---

Clang now correctly recognizes such constructs as malformed lambda
introducers and emits the expected diagnostic — for example,
“capture-default must be first” — consistent with direct initialization
cases such as:

```cpp
S s([a(42), &amp;] {});
```</pre>
</div>
</content>
</entry>
<entry>
<title>[clang] Provide a more specific diagnostic for a misplaced lambda capture-default.</title>
<updated>2020-07-18T19:35:16+00:00</updated>
<author>
<name>Bruno Ricci</name>
<email>riccibrun@gmail.com</email>
</author>
<published>2020-07-18T19:35:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=32db24a7f24236d78beaeb5cfd96b115d67a5c21'/>
<id>32db24a7f24236d78beaeb5cfd96b115d67a5c21</id>
<content type='text'>
Currently a capture-default which is not the first element in the lambda-capture
is diagnosed with a generic expected variable name or 'this' in lambda capture
list, which is true but not very helpful.

If we don't have already parsed a capture-default then a lone "&amp;" or "=" is
likely to be a misplaced capture-default, so diagnose it as such.

Differential Revision: https://reviews.llvm.org/D83681

Reviewed By: aaron.ballman
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Currently a capture-default which is not the first element in the lambda-capture
is diagnosed with a generic expected variable name or 'this' in lambda capture
list, which is true but not very helpful.

If we don't have already parsed a capture-default then a lone "&amp;" or "=" is
likely to be a misplaced capture-default, so diagnose it as such.

Differential Revision: https://reviews.llvm.org/D83681

Reviewed By: aaron.ballman
</pre>
</div>
</content>
</entry>
</feed>
