From: Daniel Jasper Date: Mon, 2 Jun 2014 09:52:08 +0000 (+0000) Subject: clang-format: Fix trailing const (etc.) with Allman brace style. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5c7f7663b274c73a85f26d82f71085dde4d06195;p=clang clang-format: Fix trailing const (etc.) with Allman brace style. Before: void someLongFunction(int someLongParameter) const { } After: void someLongFunction( int someLongParameter) const { } This fixes llvm.org/PR19912. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@210010 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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"