From e0d538f7e6046c19e014f7ceb723071267f55efd Mon Sep 17 00:00:00 2001 From: Andi-Bogdan Postelnicu Date: Wed, 26 Oct 2016 07:44:51 +0000 Subject: [PATCH] Bug 28065 - clang-format incorrectly aligns backslash. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285178 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/WhitespaceManager.cpp | 2 +- unittests/Format/FormatTest.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/Format/WhitespaceManager.cpp b/lib/Format/WhitespaceManager.cpp index 8ca307bd16..ebc72a9d45 100644 --- a/lib/Format/WhitespaceManager.cpp +++ b/lib/Format/WhitespaceManager.cpp @@ -432,7 +432,7 @@ void WhitespaceManager::alignTrailingComments(unsigned Start, unsigned End, } assert(Shift >= 0); Changes[i].Spaces += Shift; - if (i + 1 != End) + if (i + 1 != Changes.size()) Changes[i + 1].PreviousEndOfTokenColumn += Shift; Changes[i].StartOfTokenColumn += Shift; } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index f04f5e5dc0..ee08121c5a 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -11597,6 +11597,17 @@ TEST_F(ReplacementTest, SortIncludesAfterReplacement) { EXPECT_EQ(Expected, *Result); } +TEST_F(FormatTest, AllignTrailingComments) { + EXPECT_EQ("#define MACRO(V) \\\n" + " V(Rt2) /* one more char */ \\\n" + " V(Rs) /* than here */ \\\n" + "/* comment 3 */\n", + format("#define MACRO(V)\\\n" + "V(Rt2) /* one more char */ \\\n" + "V(Rs) /* than here */ \\\n" + "/* comment 3 */ \\\n", + getLLVMStyleWithColumns(40))); +} } // end namespace } // end namespace format } // end namespace clang -- 2.40.0