Commit bb6d2be
authored
[Clang] fix confusing diagnostics for lambdas with init-captures inside braced initializers (#166180)
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), &] {}};
```
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), &] {});
```1 parent 6adf993 commit bb6d2be
File tree
3 files changed
+22
-10
lines changed- clang
- docs
- lib/Parse
- test/Parser
3 files changed
+22
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
| 517 | + | |
517 | 518 | | |
518 | 519 | | |
519 | 520 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
772 | 772 | | |
773 | 773 | | |
774 | 774 | | |
775 | | - | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
776 | 778 | | |
777 | | - | |
| 779 | + | |
778 | 780 | | |
779 | 781 | | |
780 | 782 | | |
| |||
824 | 826 | | |
825 | 827 | | |
826 | 828 | | |
827 | | - | |
| 829 | + | |
828 | 830 | | |
829 | 831 | | |
830 | 832 | | |
| |||
861 | 863 | | |
862 | 864 | | |
863 | 865 | | |
864 | | - | |
| 866 | + | |
865 | 867 | | |
866 | 868 | | |
867 | 869 | | |
| |||
875 | 877 | | |
876 | 878 | | |
877 | 879 | | |
878 | | - | |
879 | | - | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
880 | 883 | | |
881 | 884 | | |
882 | 885 | | |
| |||
899 | 902 | | |
900 | 903 | | |
901 | 904 | | |
902 | | - | |
| 905 | + | |
903 | 906 | | |
904 | 907 | | |
905 | 908 | | |
906 | 909 | | |
907 | | - | |
908 | | - | |
909 | | - | |
| 910 | + | |
| 911 | + | |
910 | 912 | | |
911 | 913 | | |
912 | 914 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
0 commit comments