[PATCH] [clang-format] Fix AlwaysBreakAfterDefinitionReturnType incompatibility with BreakBeforeBraces: Stroustrup
Marek Kurdej
curdeius at gmail.com
Thu Aug 14 02:35:24 PDT 2014
- [clang-format] Fix {AlwaysBreakAfterDefinitionReturnType: true} not working with {BreakBeforeBraces: Stroustrup}.
- [clang-format] Add FIXME and check for a tok::semi or a tok::comment.
http://reviews.llvm.org/D4886
Files:
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1290,7 +1290,8 @@
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 =
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -4156,6 +4156,29 @@
"}\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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4886.12491.patch
Type: text/x-patch
Size: 1897 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140814/b92b3ecc/attachment.bin>
More information about the cfe-commits
mailing list