forked from OSchip/llvm-project
[clang-format] Fix CompactNamespaces corner case when AllowShortLambdasOnASingleLine/BraceWrapping.BeforeLambdaBody are set
In clang-format 12, `CompactNamespaces` misformatted the code when `AllowShortLambdasOnASingleLine` is set to false and `BraceWrapping.BeforeLambdaBody` is true.
Input:
```
namespace out {
namespace in {
}
} // namespace out::in
```
Expected output:
```
namespace out { namespace in {
}} // namespace out::in
```
Output from v12:
```
namespace out {
namespace in {
}
} // namespace out::in
```
Config triggering the issue:
```
---
AllowShortLambdasOnASingleLine: None
BraceWrapping:
BeforeLambdaBody : true
BreakBeforeBraces: Custom
CompactNamespaces: true
...
```
Seems there's a corner case when `AllowShortLambdasOnASingleLine` is false, and `BraceWrapping.BeforeLambdaBody` is true, that causes CompactNamespaces to stop working.
The cause was a misannotation of `{` opening brace after `namespace` as a lambda opening brace.
The regression was probably introduced with [this commit](fa0118e6e5
).
Originally contributed by Ahmed Mahdy (@aybassiouny). Thank you!
Reviewed By: Wawha, HazardyKnusperkeks
Differential Revision: https://reviews.llvm.org/D99031
This commit is contained in:
parent
0ab54c28f8
commit
6ea3d9efc5
|
@ -3830,6 +3830,21 @@ TEST_F(FormatTest, FormatsCompactNamespaces) {
|
|||
"} // namespace mid\n"
|
||||
"} // namespace out",
|
||||
Style));
|
||||
|
||||
Style.CompactNamespaces = true;
|
||||
Style.AllowShortLambdasOnASingleLine = FormatStyle::SLS_None;
|
||||
Style.BreakBeforeBraces = FormatStyle::BS_Custom;
|
||||
Style.BraceWrapping.BeforeLambdaBody = true;
|
||||
verifyFormat("namespace out { namespace in {\n"
|
||||
"}} // namespace out::in",
|
||||
Style);
|
||||
EXPECT_EQ("namespace out { namespace in {\n"
|
||||
"}} // namespace out::in",
|
||||
format("namespace out {\n"
|
||||
"namespace in {\n"
|
||||
"} // namespace in\n"
|
||||
"} // namespace out",
|
||||
Style));
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, FormatsExternC) {
|
||||
|
|
Loading…
Reference in New Issue