================ @@ -27492,6 +27492,86 @@ TEST_F(FormatTest, SpaceBetweenKeywordAndLiteral) { verifyFormat("return sizeof \"5\";"); } +TEST_F(FormatTest, BinPackBinaryOperations) { + auto Style = getLLVMStyle(); + Style.BinPackBinaryOperations = false; + + // Logical operations + verifyFormat("if (condition1 && condition2) {\n" + "}", + Style); + verifyFormat("if (condition1 && // comment\n" + " condition2 &&\n" + " (condition3 || condition4) && // comment\n" + " condition5 &&\n" + " condition6) {\n" + "}", + Style); + verifyFormat("if (loooooooooooooooooooooongcondition1 &&\n" + " loooooooooooooooooooooongcondition2) {\n" + "}", + Style); + + // Arithmetic + verifyFormat("const int result = lhs + rhs;\n", Style); + verifyFormat("const int result = loooooooooooooooooooooongop1 +\n" + " loooooooooooooooooooooongop2 +\n" + " loooooooooooooooooooooongop3;\n", + Style); + + // clang-format off + verifyFormat("const int result =\n" + " operand1 + operand2 - (operand3 + operand4) - operand5 * operand6;\n", + Style); + // clang-format on + + verifyFormat("const int result = longOperand1 +\n" + " longOperand2 -\n" + " (longOperand3 + longOperand4) -\n" + " longOperand5 * longOperand6;\n", ---------------- ameerj wrote:
@HazardyKnusperkeks Would it be acceptable to specify that this would set every operation _of the same precedence_ on individual lines if they fit? And if users report issues with the way it currently works, then we can look into resolving this https://github.com/llvm/llvm-project/pull/95013 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits