[cfe-dev] break after definition return type, but only if function can't be a one-liner?

Daniel Jasper djasper at google.com
Wed Dec 24 15:39:33 PST 2014


I am somewhat torn with regard to adding this option. Every additional
option has a certain cost associated with it (harder discovery of options,
more maintenance, more combinations of options that can lead to undesired
behavior, etc.).

Now, these costs aren't particularly high for the option you are
suggesting, but I also don't understand the gain.

AlwaysBreakAfterReturnType is mostly implemented to support GNU style. The
rationale that GNU style gives for having this style is so that it becomes
easier to grep for function names, navigate between functions, etc. This
rationale certainly doesn't apply if you exclude single-line functions. If
you don't care about grep'ing of function names, it seems fine to use what
LLVM style does and break after the return type first (before breaking
anywhere else). Can you elaborate on why you think that your proposed style
is useful?

On Wed, Dec 24, 2014 at 11:25 PM, Adam McKee <Adam.Matthew.McKee at gmail.com>
wrote:

> Hi, list :)
>
> I'm new to clang-format, and I'm really impressed with this tool.  I
> think the value of an automated tool like this is so great, that I'll
> happily let it process all my code even if it doesn't do what I want
> 100% of the time.  Most of the times when it's done something
> different from my habit, I've decided it actually looks better, and
> the only reason I wasn't formatting that way was because it would be a
> pain to do it manually.  Amazingly, there seems to only be one thing
> that makes me hesitate before running it on everything, and even this
> "issue" may not stop me from doing so.  I'd like to share my use case
> & suggested change, and see what you think.
>
> === MY USE CASE
>
> I want to allow one-liner functions
> ("AllowShortFunctionsOnASingleLine"), but if a function does not fit
> on one line I want to "BreakAfterDefinitionReturnType".  The
> configuration options don't seem to allow this, although they do what
> it says on the tin: "AlwaysBreakAfterReturnType" really means ALWAYS,
> but I don't want it always, I want it only if the function can't fit
> on a single line.  Is this actually possible now, or could it be done
> in a future version?
>
> === MY SUGGESTED CHANGE
>
> My suggestion would be to remove "AlwaysBreakAfterReturnType", and add
> "BreakAfterReturnType" with three options: "always", "never", and
> "multiline", where "multiline" means break after return type if the
> function is not eligible for writing on a single line.  Is this a
> sensible request?  For clarity, "BreakAfterReturnType=multiline" would
> be equivalent to "BreakAfterReturnType=always" unless
> "AllowShortFunctionsOnASingleLine=true".
>
> Without this change, I think I'd probably turn off
> "AlwaysBreakAfterReturnType", but I'd like to have my return types on
> their own line & (as a higher priority) have my one-liners too if
> possible.
>
> Thanks for any advice :)  It's a great tool.
>
> -Adam
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141225/c2fa416d/attachment.html>


More information about the cfe-dev mailing list