From 8c2a47d9e575d51ccf6b2f1b251597cd9c5cbd0d Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 3 Dec 2014 14:02:59 +0000 Subject: [PATCH] clang-format: Fix fake parentheses placement with comments. Before: return (a > b // comment1 // comment2 || c); After: return (a > b // comment1 // comment2 || c); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223234 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 2 +- unittests/Format/FormatTest.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 3b04e49ba5..9b215dcd47 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1217,7 +1217,7 @@ private: Start->StartsBinaryExpression = true; if (Current) { FormatToken *Previous = Current->Previous; - if (Previous->is(tok::comment) && Previous->Previous) + while (Previous->is(tok::comment) && Previous->Previous) Previous = Previous->Previous; ++Previous->FakeRParens; if (Precedence > prec::Unknown) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 148c2f98ff..ea5f67ca49 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3337,6 +3337,13 @@ TEST_F(FormatTest, NoOperandAlignment) { " + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n" " * cccccccccccccccccccccccccccccccccccc;", Style); + + Style.AlignAfterOpenBracket = false; + verifyFormat("return (a > b\n" + " // comment1\n" + " // comment2\n" + " || c);", + Style); } TEST_F(FormatTest, BreakingBeforeNonAssigmentOperators) { -- 2.40.0