r210010 - clang-format: Fix trailing const (etc.) with Allman brace style.
Daniel Jasper
djasper at google.com
Mon Jun 2 02:52:09 PDT 2014
Author: djasper
Date: Mon Jun 2 04:52:08 2014
New Revision: 210010
URL: http://llvm.org/viewvc/llvm-project?rev=210010&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=210010&r1=210009&r2=210010&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jun 2 04:52:08 2014
@@ -1329,8 +1329,8 @@ unsigned TokenAnnotator::splitPenalty(co
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.
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=210010&r1=210009&r2=210010&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jun 2 04:52:08 2014
@@ -3469,6 +3469,13 @@ TEST_F(FormatTest, BreaksFunctionDeclara
" 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"
More information about the cfe-commits
mailing list