Commit 4287fc3
committed
[clang-format] Fix formatting of requires expressions in braced initializers
When clang-format encountered a requires expression inside a braced
initializer (e.g., `bool foo{requires { 0; }};`), it would incorrectly
format the code to the following:
bool bar{requires {0;
}
}
;
The issue was that UnwrappedLineParser::parseBracedList had no explicit
handling for the requires keyword, so it would just call nextToken()
instead of properly parsing the requires expression.
This fix adds a case for tok::kw_requires in parseBracedList, calling
parseRequiresExpression to handle it correctly, matching the existing
behavior in parseParens [1].
Fixes #162984.
[1]: https://github.com/llvm/llvm-project/blob/7eee67202378932d03331ad04e7d07ed4d988381/clang/lib/Format/UnwrappedLineParser.cpp#L2713-L2718
Signed-off-by: Ruoyu Zhong <[email protected]>1 parent 7eee672 commit 4287fc3
File tree
2 files changed
+12
-0
lines changed- clang
- lib/Format
- unittests/Format
2 files changed
+12
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2569 | 2569 | | |
2570 | 2570 | | |
2571 | 2571 | | |
| 2572 | + | |
| 2573 | + | |
| 2574 | + | |
| 2575 | + | |
| 2576 | + | |
| 2577 | + | |
2572 | 2578 | | |
2573 | 2579 | | |
2574 | 2580 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26973 | 26973 | | |
26974 | 26974 | | |
26975 | 26975 | | |
| 26976 | + | |
| 26977 | + | |
| 26978 | + | |
| 26979 | + | |
| 26980 | + | |
| 26981 | + | |
26976 | 26982 | | |
26977 | 26983 | | |
26978 | 26984 | | |
| |||
0 commit comments