summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Format/TokenAnnotator.cpp4
-rw-r--r--unittests/Format/FormatTest.cpp7
2 files changed, 9 insertions, 2 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 902cbb8f44..a66f1dfcb2 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -1329,8 +1329,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
return 150;
}
- if (Right.Type == TT_TrailingAnnotation && Right.Next &&
- Right.Next->isNot(tok::l_paren)) {
+ if (Right.Type == TT_TrailingAnnotation &&
+ (!Right.Next || Right.Next->isNot(tok::l_paren))) {
// Generally, breaking before a trailing annotation is bad unless it is
// function-like. It seems to be especially preferable to keep standard
// annotations (i.e. "const", "final" and "override") on the same line.
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 8aa256053f..9a91b9ef04 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -3469,6 +3469,13 @@ TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {
" int parameter) const override {}",
Style);
+ Style.BreakBeforeBraces = FormatStyle::BS_Allman;
+ verifyFormat("void someLongFunction(\n"
+ " int someLongParameter) const\n"
+ "{\n"
+ "}",
+ Style);
+
// Unless these are unknown annotations.
verifyFormat("void SomeFunction(aaaaaaaaaa aaaaaaaaaaaaaaa,\n"
" aaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"