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

Adam McKee Adam.Matthew.McKee at gmail.com
Wed Dec 24 14:25:01 PST 2014


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



More information about the cfe-dev mailing list