r215633 - clang-format: Fix AlwaysBreakAfterDefinitionReturnType in Stroutrup style
Daniel Jasper
djasper at google.com
Thu Aug 14 04:36:04 PDT 2014
Author: djasper
Date: Thu Aug 14 06:36:03 2014
New Revision: 215633
URL: http://llvm.org/viewvc/llvm-project?rev=215633&view=rev
Log:
clang-format: Fix AlwaysBreakAfterDefinitionReturnType in Stroutrup style
Before:
template <class T>
T *f(T &c) // Problem here: no line break before f
{
return NULL;
}
After:
template <class T>
T *
f(T &c)
{
return NULL;
}
Patch by Marek Kurdej, thank you!
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=215633&r1=215632&r2=215633&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Aug 14 06:36:03 2014
@@ -1305,7 +1305,9 @@ void TokenAnnotator::calculateFormatting
if (Style.AlwaysBreakAfterDefinitionReturnType &&
InFunctionDecl && Current->Type == TT_FunctionDeclarationName &&
- Line.Last->is(tok::l_brace)) // Only for definitions.
+ !Line.Last->isOneOf(tok::semi, tok::comment)) // Only for definitions.
+ // FIXME: Line.Last points to other characters than tok::semi
+ // and tok::lbrace.
Current->MustBreakBefore = true;
Current->CanBreakBefore =
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=215633&r1=215632&r2=215633&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Aug 14 06:36:03 2014
@@ -4156,6 +4156,29 @@ TEST_F(FormatTest, AlwaysBreakAfterDefin
"}\n"
"const char *bar(void);\n", // No break here.
AfterType);
+ verifyFormat("template <class T>\n"
+ "T *\n"
+ "f(T &c) {\n" // Break here.
+ " return NULL;\n"
+ "}\n"
+ "template <class T> T *f(T &c);\n", // No break here.
+ AfterType);
+ AfterType.BreakBeforeBraces = FormatStyle::BS_Stroustrup;
+ verifyFormat("const char *\n"
+ "f(void)\n" // Break here.
+ "{\n"
+ " return \"\";\n"
+ "}\n"
+ "const char *bar(void);\n", // No break here.
+ AfterType);
+ verifyFormat("template <class T>\n"
+ "T *\n" // Problem here: no line break
+ "f(T &c)\n" // Break here.
+ "{\n"
+ " return NULL;\n"
+ "}\n"
+ "template <class T> T *f(T &c);\n", // No break here.
+ AfterType);
}
TEST_F(FormatTest, AlwaysBreakBeforeMultilineStrings) {
More information about the cfe-commits
mailing list