<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>From what I've seen, Clang's style is to not break after the return type even in a function declaration. As you say, it's sort of an issue if the declarations stack up next to each other, but we generally don't do that anyway, and <i>couldn't</i> do it if the functions are doc-commented.</div><div><br></div><div>Jordan</div><div><br></div><br><div><div>On May 6, 2013, at 1:27 , Daniel Jasper <<a href="mailto:djasper@google.com">djasper@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Author: djasper<br>Date: Mon May 6 03:27:33 2013<br>New Revision: 181187<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=181187&view=rev">http://llvm.org/viewvc/llvm-project?rev=181187&view=rev</a><br>Log:<br>Change indentation when breaking after a type.<br><br>clang-format did not indent any declarations/definitions when breaking<br>after the type. With this change, it indents for all declarations but<br>does not indent for function definitions, i.e.:<br><br>Before:<br>const SomeLongTypeName&<br>some_long_variable_name;<br>typedef SomeLongTypeName<br>SomeLongTypeAlias;<br>const SomeLongReturnType*<br>SomeLongFunctionName();<br>const SomeLongReturnType*<br>SomeLongFunctionName() { ... }<br><br>After:<br>const SomeLongTypeName&<br> some_long_variable_name;<br>typedef SomeLongTypeName<br> SomeLongTypeAlias;<br>const SomeLongReturnType*<br> SomeLongFunctionName();<br>const SomeLongReturnType*<br>SomeLongFunctionName() { ... }<br><br>While it might seem inconsistent to indent function declarations, but<br>not definitions, there are two reasons for that:<br>- Function declarations are very similar to declarations of function<br>type variables, so there is another side to consistency to consider.<br>- There can be many function declarations on subsequent lines and not<br>indenting can make them harder to identify. Function definitions<br>are already separated by their body and not indenting<br>makes the function name slighly easier to find.<br><br>Modified:<br> cfe/trunk/lib/Format/Format.cpp<br> cfe/trunk/lib/Format/TokenAnnotator.cpp<br> cfe/trunk/lib/Format/TokenAnnotator.h<br> cfe/trunk/unittests/Format/FormatTest.cpp<br><br>Modified: cfe/trunk/lib/Format/Format.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=181187&r1=181186&r2=181187&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=181187&r1=181186&r2=181187&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/Format/Format.cpp (original)<br>+++ cfe/trunk/lib/Format/Format.cpp Mon May 6 03:27:33 2013<br>@@ -359,7 +359,8 @@ private:<br> State.Stack.back().VariablePos != 0) {<br> State.Column = State.Stack.back().VariablePos;<br> } else if (Previous.ClosesTemplateDeclaration ||<br>- (Current.Type == TT_StartOfName && State.ParenLevel == 0)) {<br>+ (Current.Type == TT_StartOfName && State.ParenLevel == 0 &&<br>+ Line.StartsDefinition)) {<br> State.Column = State.Stack.back().Indent;<br> } else if (Current.Type == TT_ObjCSelectorName) {<br> if (State.Stack.back().ColonPos > Current.FormatTok.TokenLength) {<br><br>Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=181187&r1=181186&r2=181187&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=181187&r1=181186&r2=181187&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)<br>+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon May 6 03:27:33 2013<br>@@ -245,24 +245,25 @@ private:<br> }<br><br> bool parseBrace() {<br>- // Lines are fine to end with '{'.<br>- if (CurrentToken == NULL)<br>- return true;<br>- ScopedContextCreator ContextCreator(*this, tok::l_brace, 1);<br>- AnnotatedToken *Left = CurrentToken->Parent;<br>- while (CurrentToken != NULL) {<br>- if (CurrentToken->is(tok::r_brace)) {<br>- Left->MatchingParen = CurrentToken;<br>- CurrentToken->MatchingParen = Left;<br>- next();<br>- return true;<br>+ if (CurrentToken != NULL) {<br>+ ScopedContextCreator ContextCreator(*this, tok::l_brace, 1);<br>+ AnnotatedToken *Left = CurrentToken->Parent;<br>+ while (CurrentToken != NULL) {<br>+ if (CurrentToken->is(tok::r_brace)) {<br>+ Left->MatchingParen = CurrentToken;<br>+ CurrentToken->MatchingParen = Left;<br>+ next();<br>+ return true;<br>+ }<br>+ if (CurrentToken->isOneOf(tok::r_paren, tok::r_square))<br>+ return false;<br>+ updateParameterCount(Left, CurrentToken);<br>+ if (!consumeToken())<br>+ return false;<br> }<br>- if (CurrentToken->isOneOf(tok::r_paren, tok::r_square))<br>- return false;<br>- updateParameterCount(Left, CurrentToken);<br>- if (!consumeToken())<br>- return false;<br> }<br>+ // No closing "}" found, this probably starts a definition.<br>+ Line.StartsDefinition = true;<br> return true;<br> }<br><br><br>Modified: cfe/trunk/lib/Format/TokenAnnotator.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.h?rev=181187&r1=181186&r2=181187&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.h?rev=181187&r1=181186&r2=181187&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/Format/TokenAnnotator.h (original)<br>+++ cfe/trunk/lib/Format/TokenAnnotator.h Mon May 6 03:27:33 2013<br>@@ -209,8 +209,8 @@ public:<br> AnnotatedLine(const UnwrappedLine &Line)<br> : First(Line.Tokens.front()), Level(Line.Level),<br> InPPDirective(Line.InPPDirective),<br>- MustBeDeclaration(Line.MustBeDeclaration),<br>- MightBeFunctionDecl(false) {<br>+ MustBeDeclaration(Line.MustBeDeclaration), MightBeFunctionDecl(false),<br>+ StartsDefinition(false) {<br> assert(!Line.Tokens.empty());<br> AnnotatedToken *Current = &First;<br> for (std::list<FormatToken>::const_iterator I = ++Line.Tokens.begin(),<br>@@ -226,7 +226,8 @@ public:<br> : First(Other.First), Type(Other.Type), Level(Other.Level),<br> InPPDirective(Other.InPPDirective),<br> MustBeDeclaration(Other.MustBeDeclaration),<br>- MightBeFunctionDecl(Other.MightBeFunctionDecl) {<br>+ MightBeFunctionDecl(Other.MightBeFunctionDecl),<br>+ StartsDefinition(Other.StartsDefinition) {<br> Last = &First;<br> while (!Last->Children.empty()) {<br> Last->Children[0].Parent = Last;<br>@@ -242,6 +243,7 @@ public:<br> bool InPPDirective;<br> bool MustBeDeclaration;<br> bool MightBeFunctionDecl;<br>+ bool StartsDefinition;<br> };<br><br> inline prec::Level getPrecedence(const AnnotatedToken &Tok) {<br><br>Modified: cfe/trunk/unittests/Format/FormatTest.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=181187&r1=181186&r2=181187&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=181187&r1=181186&r2=181187&view=diff</a><br>==============================================================================<br>--- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon May 6 03:27:33 2013<br>@@ -1520,7 +1520,7 @@ TEST_F(FormatTest, MixingPreprocessorDir<br> TEST_F(FormatTest, LayoutStatementsAroundPreprocessorDirectives) {<br> EXPECT_EQ("int\n"<br> "#define A\n"<br>- "a;",<br>+ " a;",<br> format("int\n#define A\na;"));<br> verifyFormat("functionCallTo(\n"<br> " someOtherFunction(\n"<br>@@ -1713,7 +1713,7 @@ TEST_F(FormatTest, MemoizationTests) {<br> "CFRunLoopTimerCreate(CFAllocatorRef allocato, CFAbsoluteTime fireDate,\n"<br> " CFTimeInterval interval, CFOptionFlags flags,\n"<br> " CFIndex order, CFRunLoopTimerCallBack callout,\n"<br>- " CFRunLoopTimerContext *context);");<br>+ " CFRunLoopTimerContext *context) {}");<br><br> // Deep nesting somewhat works around our memoization.<br> verifyFormat(<br>@@ -1755,8 +1755,9 @@ TEST_F(FormatTest, BreaksFunctionDeclara<br> " Cccccccccccccc cccccccccccccc);");<br><br> // 2) break after return type.<br>- verifyFormat("Aaaaaaaaaaaaaaaaaaaaaaaa\n"<br>- "bbbbbbbbbbbbbb(Cccccccccccccc cccccccccccccccccccccccccc);");<br>+ verifyFormat(<br>+ "Aaaaaaaaaaaaaaaaaaaaaaaa\n"<br>+ " bbbbbbbbbbbbbb(Cccccccccccccc cccccccccccccccccccccccccc);");<br><br> // 3) break after (.<br> verifyFormat(<br>@@ -1766,8 +1767,8 @@ TEST_F(FormatTest, BreaksFunctionDeclara<br> // 4) break before after nested name specifiers.<br> verifyFormat(<br> "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"<br>- "SomeClasssssssssssssssssssssssssssssssssssssss::\n"<br>- " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(Cccccccccccccc cccccccccc);");<br>+ " SomeClasssssssssssssssssssssssssssssssssssssss::\n"<br>+ " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(Cccccccccccccc cccccccccc);");<br><br> // However, there are exceptions, if a sufficient amount of lines can be<br> // saved.<br>@@ -1780,9 +1781,9 @@ TEST_F(FormatTest, BreaksFunctionDeclara<br> " Cccccccccccccc cccccccccc);");<br> verifyFormat(<br> "Aaaaaaaaaaaaaaaaaa\n"<br>- "bbbbbbbbbbbbbb(Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc,\n"<br>- " Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc,\n"<br>- " Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc);");<br>+ " bbbbbbbbbbb(Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc,\n"<br>+ " Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc,\n"<br>+ " Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc);");<br> verifyFormat(<br> "Aaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(Cccccccccccccc cccccccccc,\n"<br> " Cccccccccccccc cccccccccc,\n"<br>@@ -1954,12 +1955,9 @@ TEST_F(FormatTest, DoesNotBreakTrailingA<br> " aaaaaaaaaaaaaaaaaaaaaaaaa));");<br> verifyFormat("bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"<br> " __attribute__((unused));");<br>-<br>- // FIXME: This is bad indentation, but generally hard to distinguish from a<br>- // function declaration.<br> verifyFormat(<br> "bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"<br>- "GUARDED_BY(aaaaaaaaaaaa);");<br>+ " GUARDED_BY(aaaaaaaaaaaa);");<br> }<br><br> TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) {<br>@@ -2121,8 +2119,8 @@ TEST_F(FormatTest, DeclarationsOfMultipl<br> // FIXME: If multiple variables are defined, the "*" needs to move to the new<br> // line. Also fix indent for breaking after the type, this looks bad.<br> verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *\n"<br>- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaa,\n"<br>- " *b = bbbbbbbbbbbbbbbbbbb;");<br>+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaa,\n"<br>+ " *b = bbbbbbbbbbbbbbbbbbb;");<br><br> // Not ideal, but pointer-with-type does not allow much here.<br> verifyGoogleFormat(<br>@@ -2707,6 +2705,19 @@ TEST_F(FormatTest, FormatsFunctionTypes)<br> }<br><br> TEST_F(FormatTest, BreaksLongDeclarations) {<br>+ verifyFormat("typedef LoooooooooooooooooooooooooooooooooooooooongType\n"<br>+ " AnotherNameForTheLongType;");<br>+ verifyFormat("LoooooooooooooooooooooooooooooooooooooooongType\n"<br>+ " LoooooooooooooooooooooooooooooooooooooooongVariable;");<br>+ verifyFormat("LoooooooooooooooooooooooooooooooooooooooongReturnType\n"<br>+ " LoooooooooooooooooooooooooooooooongFunctionDeclaration();");<br>+ verifyFormat("LoooooooooooooooooooooooooooooooooooooooongReturnType\n"<br>+ "LooooooooooooooooooooooooooooooooooongFunctionDefinition() {}");<br>+<br>+ // FIXME: Without the comment, this breaks after "(".<br>+ verifyFormat("LoooooooooooooooooooooooooooooooooooooooongType // break\n"<br>+ " (*LoooooooooooooooooooooooooooongFunctionTypeVarialbe)();");<br>+<br> verifyFormat("int *someFunction(int LoooooooooooooooooooongParam1,\n"<br> " int LoooooooooooooooooooongParam2) {}");<br> verifyFormat(<br>@@ -2722,7 +2733,7 @@ TEST_F(FormatTest, BreaksLongDeclaration<br> " AnotherLongParameterName) {}");<br> verifyFormat(<br> "aaaaaaaaaaaaaaaa::aaaaaaaaaaaaaaaa<aaaaaaaaaaaaa, aaaaaaaaaaaa>\n"<br>- "aaaaaaaaaaaaaaaaaaaaaaa;");<br>+ " aaaaaaaaaaaaaaaaaaaaaaa;");<br><br> verifyGoogleFormat(<br> "TypeSpecDecl* TypeSpecDecl::Create(ASTContext& C, DeclContext* DC,\n"<br><br><br>_______________________________________________<br>cfe-commits mailing list<br><a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits<br></blockquote></div><br></body></html>