即使使用允许Shortlambdasonasinglineleline,Short Lambda被Clang-Format分开
我有此代码块:
int main() {
SomeType something1(
[](const Input& i) -> Output { return Output {1, 2}; },
[](const Input& i) -> Output { return Output {1, 2}; }
);
SomeType something2(
[](const Input& i) -> Output { return Output (1, 2); },
[](const Input& i) -> Output { return Output (1, 2); }
);
}
当我尝试使用以下设置clang-format
时:
AlignAfterOpenBracket: Align
AllowShortBlocksOnASingleLine: Always
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
它会产生此输出(请注意somets of sosity1
and sosity2
get get格式化的方式不同):
int main() {
SomeType something1(
[](const Input &i) -> Output {
return Output{1, 2};
},
[](const Input &i) -> Output {
return Output{1, 2};
});
SomeType something2([](const Input &i) -> Output { return Output(1, 2); },
[](const Input &i) -> Output { return Output(1, 2); });
}
我将问题隔离到something 1
中的支撑初始机。
- 如何使clang-format输出
something1
和something 2
以> sosity2
的样式> sosity2 - 为什么clang-format解析/对其进行不同? (为了我自己的理解)
I have this code block:
int main() {
SomeType something1(
[](const Input& i) -> Output { return Output {1, 2}; },
[](const Input& i) -> Output { return Output {1, 2}; }
);
SomeType something2(
[](const Input& i) -> Output { return Output (1, 2); },
[](const Input& i) -> Output { return Output (1, 2); }
);
}
And when I try to clang-format
with these settings:
AlignAfterOpenBracket: Align
AllowShortBlocksOnASingleLine: Always
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
It produces this output (note that something1
and something2
get formatted differently):
int main() {
SomeType something1(
[](const Input &i) -> Output {
return Output{1, 2};
},
[](const Input &i) -> Output {
return Output{1, 2};
});
SomeType something2([](const Input &i) -> Output { return Output(1, 2); },
[](const Input &i) -> Output { return Output(1, 2); });
}
I've isolated the issue to the brace initialiser in something1
.
- How do I make clang-format output both
something1
andsomething2
in the style ofsomething2
- Why is clang-format parsing/treating them differently? (For my own understanding)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论