From 411d4e186ce6fff47c41aaa20cdcbcf7cc2488fd Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 11 Nov 2014 23:04:51 +0000 Subject: [PATCH] clang-format: Improve handling of comments in binary expressions. Before: b = a && // Comment b.c && d; After: b = a && // Comment b.c && d; This fixes llvm.org/PR21535. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221727 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 3 +-- unittests/Format/FormatTest.cpp | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 715cbf0a48..8ec8f58d14 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1149,8 +1149,7 @@ public: Current->OperatorIndex = OperatorIndex; ++OperatorIndex; } - - next(/*SkipPastLeadingComments=*/false); + next(/*SkipPastLeadingComments=*/Precedence > 0); } } } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 1f95a89893..37c3c0e752 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3118,6 +3118,9 @@ TEST_F(FormatTest, LineBreakingInBinaryExpressions) { verifyFormat("if ((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n" " bbbbbbbbbbbbbbbbbb) && // aaaaaaaaaaaaaaaa\n" " cccccc) {\n}"); + verifyFormat("b = a &&\n" + " // Comment\n" + " b.c && d;"); // If the LHS of a comparison is not a binary expression itself, the // additional linebreak confuses many people. -- 2.50.1