From eec240b1ce3fe37bccdb160c194ff1ffa820b32d Mon Sep 17 00:00:00 2001 From: Daniel Jasper <djasper@google.com> Date: Thu, 16 Oct 2014 09:10:11 +0000 Subject: [PATCH] clang-format: Fix behavior with comments before conditional expressions Before: SomeFunction(aaaaaaaaaaaaaaaaa, // comment. ccccccccccccccccc ? aaaaaaaaaaaaaaaaaaaa : bbbbbbbbbbbbbbbbbbbb); After: SomeFunction(aaaaaaaaaaaaaaaaa, // comment. ccccccccccccccccc ? aaaaaaaaaaaaaaaaaaaa : bbbbbbbbbbbbbbbbbbbb); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219921 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 3 +++ unittests/Format/FormatTest.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index a8e2c5556a8..c83ec604758 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1174,6 +1174,9 @@ private: } void parseConditionalExpr() { + while (Current && Current->isTrailingComment()) { + next(); + } FormatToken *Start = Current; parse(prec::LogicalOr); if (!Current || !Current->is(tok::question)) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index b195df4291c..aebfef6fbea 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4060,6 +4060,12 @@ TEST_F(FormatTest, BreaksConditionalExpressions) { " ?: aaaaaaaaaaaaaaa);\n" "}", NoBinPacking); + + verifyFormat("SomeFunction(aaaaaaaaaaaaaaaaa,\n" + " // comment.\n" + " ccccccccccccccccccccccccccccccccccccccc\n" + " ? aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" + " : bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);"); } TEST_F(FormatTest, BreaksConditionalExpressionsAfterOperator) { -- GitLab