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: http://review.tizen.org/git/?a=commitdiff_plain;h=e3f907fdedc365fdd4dd2382db5873aa73601c1f;p=platform%2Fupstream%2Fllvm.git 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. llvm-svn: 210010 --- diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 902cbb8..a66f1dfc 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 8aa2560..9a91b9e 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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"