This revision was automatically updated to reflect the committed changes. Closed by commit rL293548: [clang-format] Fix regression that breaks comments without a comment prefix (authored by krasimir).
Changed prior to commit: https://reviews.llvm.org/D29298?vs=86328&id=86331#toc Repository: rL LLVM https://reviews.llvm.org/D29298 Files: cfe/trunk/lib/Format/BreakableToken.cpp cfe/trunk/unittests/Format/FormatTest.cpp Index: cfe/trunk/lib/Format/BreakableToken.cpp =================================================================== --- cfe/trunk/lib/Format/BreakableToken.cpp +++ cfe/trunk/lib/Format/BreakableToken.cpp @@ -642,7 +642,11 @@ Prefix.resize(Lines.size()); OriginalPrefix.resize(Lines.size()); for (size_t i = FirstLineIndex, e = Lines.size(); i < e; ++i) { - StringRef IndentPrefix = getLineCommentIndentPrefix(Lines[i]); + // We need to trim the blanks in case this is not the first line in a + // multiline comment. Then the indent is included in Lines[i]. + StringRef IndentPrefix = + getLineCommentIndentPrefix(Lines[i].ltrim(Blanks)); + assert(IndentPrefix.startswith("//")); OriginalPrefix[i] = Prefix[i] = IndentPrefix; if (Lines[i].size() > Prefix[i].size() && isAlphanumeric(Lines[i][Prefix[i].size()])) { Index: cfe/trunk/unittests/Format/FormatTest.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -1386,6 +1386,18 @@ "#define XXX // q w e r\n" " // t y u i", format("#define XXX //q w e r t y u i", getLLVMStyleWithColumns(22))); + EXPECT_EQ("{\n" + " //\n" + " //\\\n" + " // long 1 2 3 4\n" + " // 5\n" + "}", + format("{\n" + " //\n" + " //\\\n" + " // long 1 2 3 4 5\n" + "}", + getLLVMStyleWithColumns(20))); } TEST_F(FormatTest, PreservesHangingIndentInCxxComments) {
Index: cfe/trunk/lib/Format/BreakableToken.cpp =================================================================== --- cfe/trunk/lib/Format/BreakableToken.cpp +++ cfe/trunk/lib/Format/BreakableToken.cpp @@ -642,7 +642,11 @@ Prefix.resize(Lines.size()); OriginalPrefix.resize(Lines.size()); for (size_t i = FirstLineIndex, e = Lines.size(); i < e; ++i) { - StringRef IndentPrefix = getLineCommentIndentPrefix(Lines[i]); + // We need to trim the blanks in case this is not the first line in a + // multiline comment. Then the indent is included in Lines[i]. + StringRef IndentPrefix = + getLineCommentIndentPrefix(Lines[i].ltrim(Blanks)); + assert(IndentPrefix.startswith("//")); OriginalPrefix[i] = Prefix[i] = IndentPrefix; if (Lines[i].size() > Prefix[i].size() && isAlphanumeric(Lines[i][Prefix[i].size()])) { Index: cfe/trunk/unittests/Format/FormatTest.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -1386,6 +1386,18 @@ "#define XXX // q w e r\n" " // t y u i", format("#define XXX //q w e r t y u i", getLLVMStyleWithColumns(22))); + EXPECT_EQ("{\n" + " //\n" + " //\\\n" + " // long 1 2 3 4\n" + " // 5\n" + "}", + format("{\n" + " //\n" + " //\\\n" + " // long 1 2 3 4 5\n" + "}", + getLLVMStyleWithColumns(20))); } TEST_F(FormatTest, PreservesHangingIndentInCxxComments) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits