clang-format stack all if-statement arguments if they are too long

后端 未结 2 751
忘掉有多难
忘掉有多难 2021-01-19 13:49

I have an if statement that has several ored arguments. I have stacked them vertically as below for readability.

    if (health.fla         


        
相关标签:
2条回答
  • 2021-01-19 14:24

    Not directly, but you can achieve something like it with BreakBeforeBinaryOperators. Try setting this value to NonAssignment. This will put your || operators before each additional condition, though, not after them.

    0 讨论(0)
  • 2021-01-19 14:29

    The only solution I've found is usage pair of // clang-format off and // clang-format on comments. E.g.

    // clang-format off
    if (health.flag_a || 
       health.flag_b ||
       health.flag_c ||
       health.flag_d ||
       health.flag_e ||
       health.flag_f ||
       health.flag_g ||
       health.flag_h ||
       health.flag_i ||
       health.flag_k) {
    do_something();
    return false;
    }
    // clang-format on
    

    Yes, this is not a solution at all, but at least it prevents your stacked conditions from being re-formatted by clang-format.

    0 讨论(0)
提交回复
热议问题