c++ - clang-format:如何防止下一行的所有函数参数?

标签 c++ clang-format

我有一个 C++ 函数调用,我手动和有意格式化为 这个:

DoSomethingForAPurposeThatCausesALongFunctionName(
    arg_0,
    arg_1,
    arg_2);

clang-format 想像这样重新格式化它:

DoSomethingForAPurposeThatCausesALongFunctionName(
    arg_0, arg_1, arg_2)

我不想要这个。 AllowAllParametersOfDeclarationOnNextLine 似乎 控制函数声明的这种行为,但是函数调用呢? 有相应的设置吗?

我的 .clang-format 看起来像这样:

BasedOnStyle: Google
BinPackArguments: false
BinPackParameters: false
AllowAllParametersOfDeclarationOnNextLine: false
AlignAfterOpenBracket: AlwaysBreak

最佳答案

我也有兴趣防止在同一行上出现多个参数,但在 fun( 行下方。就我而言,我不介意第一个参数是否仍在同一行作为 fun(。我只是希望它们要么都在 fun( 行上,要么全部堆叠起来。

我能够通过将 PenaltyBreakBeforeFirstCallParameter 增加到 100 来实现这一点。 据推测,您可能需要不同的值,具体取决于您的其他惩罚设置。

这会产生:

fun(my_long_argument_0,
    my_long_argument_1,
    my_long_argument_2);

在你的例子中,假设 DoSomethingForAPurposeThatCausesALongFunctionName(arg_0, 对于一行来说太长了,它会产生:

DoSomethingForAPurposeThatCausesALongFunctionName(
    arg_0,
    arg_1,
    arg_2);

关于c++ - clang-format:如何防止下一行的所有函数参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38635106/

相关文章:

c++ - [L,R] 中具有奇数个奇因数的数字的个数

c++ - 函数参数延续

clang 格式缩进函数参数/参数总是带有 4 个空格

c++ - clang-format 可以为我对齐 #defines block 吗?

c++ - 每行一个 Clang 格式数组初始值设定项

c++ - 使用 DirectXTK/DirectXMath 变换平面

c++ - 类方法在继承中不能正确调用

c++ - std::optional<T> 和采用对 T 的非常量引用的函数

c++ - 多种数据类型的C++列表。遗产?

clang-format - clang-format :如果语句溢出,则将参数和参数强制为一行-每行