This revision was automatically updated to reflect the committed changes. Closed by commit rG06763ea5d8f9: [clang-format] Ignore first token when finding MustBreak (authored by rymiel).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D150614/new/ https://reviews.llvm.org/D150614 Files: clang/lib/Format/UnwrappedLineFormatter.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -13832,6 +13832,20 @@ "}", format("A()\n:b(0)\n{\n}", NoColumnLimit)); + FormatStyle NoColumnLimitWrapAfterFunction = NoColumnLimit; + NoColumnLimitWrapAfterFunction.BreakBeforeBraces = FormatStyle::BS_Custom; + NoColumnLimitWrapAfterFunction.BraceWrapping.AfterFunction = true; + verifyFormat("class C {\n" + "#pragma foo\n" + " int foo { return 0; }\n" + "};", + NoColumnLimitWrapAfterFunction); + verifyFormat("class C {\n" + "#pragma foo\n" + " void foo {}\n" + "};", + NoColumnLimitWrapAfterFunction); + FormatStyle DoNotMergeNoColumnLimit = NoColumnLimit; DoNotMergeNoColumnLimit.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; @@ -20120,9 +20134,7 @@ " int i = 5;\n" " }\n" "#ifdef _DEBUG\n" - "void bar()\n" - " {\n" - " }\n" + "void bar() {}\n" "#else\n" "void bar()\n" " {\n" Index: clang/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- clang/lib/Format/UnwrappedLineFormatter.cpp +++ clang/lib/Format/UnwrappedLineFormatter.cpp @@ -888,7 +888,10 @@ } bool containsMustBreak(const AnnotatedLine *Line) { - for (const FormatToken *Tok = Line->First; Tok; Tok = Tok->Next) + assert(Line->First); + // Ignore the first token, because in this situation, it applies more to the + // last token of the previous line. + for (const FormatToken *Tok = Line->First->Next; Tok; Tok = Tok->Next) if (Tok->MustBreakBefore) return true; return false;
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -13832,6 +13832,20 @@ "}", format("A()\n:b(0)\n{\n}", NoColumnLimit)); + FormatStyle NoColumnLimitWrapAfterFunction = NoColumnLimit; + NoColumnLimitWrapAfterFunction.BreakBeforeBraces = FormatStyle::BS_Custom; + NoColumnLimitWrapAfterFunction.BraceWrapping.AfterFunction = true; + verifyFormat("class C {\n" + "#pragma foo\n" + " int foo { return 0; }\n" + "};", + NoColumnLimitWrapAfterFunction); + verifyFormat("class C {\n" + "#pragma foo\n" + " void foo {}\n" + "};", + NoColumnLimitWrapAfterFunction); + FormatStyle DoNotMergeNoColumnLimit = NoColumnLimit; DoNotMergeNoColumnLimit.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; @@ -20120,9 +20134,7 @@ " int i = 5;\n" " }\n" "#ifdef _DEBUG\n" - "void bar()\n" - " {\n" - " }\n" + "void bar() {}\n" "#else\n" "void bar()\n" " {\n" Index: clang/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- clang/lib/Format/UnwrappedLineFormatter.cpp +++ clang/lib/Format/UnwrappedLineFormatter.cpp @@ -888,7 +888,10 @@ } bool containsMustBreak(const AnnotatedLine *Line) { - for (const FormatToken *Tok = Line->First; Tok; Tok = Tok->Next) + assert(Line->First); + // Ignore the first token, because in this situation, it applies more to the + // last token of the previous line. + for (const FormatToken *Tok = Line->First->Next; Tok; Tok = Tok->Next) if (Tok->MustBreakBefore) return true; return false;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits