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

后端 未结 2 750
忘掉有多难
忘掉有多难 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: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.

提交回复
热议问题