summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/UnwrappedLineFormatter.cpp5
-rw-r--r--clang/unittests/Format/FormatTest.cpp18
2 files changed, 19 insertions, 4 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index ee0de2c8e20d..33be74dfe1b9 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -888,7 +888,10 @@ private:
}
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;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index dec0ea72b58a..942c6259015e 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -13832,6 +13832,20 @@ TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {
"}",
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 @@ TEST_F(FormatTest, WhitesmithsBraceBreaking) {
" int i = 5;\n"
" }\n"
"#ifdef _DEBUG\n"
- "void bar()\n"
- " {\n"
- " }\n"
+ "void bar() {}\n"
"#else\n"
"void bar()\n"
" {\n"