[cfe-dev] clang-format and PenaltyReturnTypeOnItsOwnLine?

Daniel Jasper djasper at google.com
Mon Sep 2 02:35:01 PDT 2013


On Fri, Aug 30, 2013 at 9:18 PM, Leif Hedstrom <zwoop at apache.org> wrote:

> On Aug 19, 2013, at 6:59 AM, Leif Hedstrom <zwoop at apache.org> wrote:
>
> > On Aug 19, 2013, at 3:08 AM, Daniel Jasper <djasper at google.com> wrote:
> >
> >> Yes, clang-format currently does not have an option that says "always
> break after a function's return type". It
> >
> > Ah, alright, so at least I'm not doing it wrong :).
> >
> >> should be fairly easy to add, though. Does your coding style prescribe
> this for definitions only or also for declarations?
> >
> >
> > Definitions only.
>
> Sorry for not following up on this. Is it worth filing an RFE issue on
> this? Is it something that others than just me would find useful?


I don't know. I have not seen coding style that do this, but I don't doubt
that they exist.


> Is this a feature that a mere mortal (like me…) could contribute?
>

I don't see why not. Basically you need to add a corresponding if-statement
to TokenAnnotator::calculateFormattingInformation()
(lib/Format/TokenAnnotator.cpp) that sets MustBreakBefore of the first
Token of the function name accordingly. The if-statement itself is probably
quite similar to the code-path the returns
Style.PenaltyReturnTypeOnItsOwnLine in TokenAnnotator::splitPenalty(). All
that would need to be guarded by a new style flag of type bool (see r188793
for an example of how to add additional flags).

Cheers,
>
> -- Leif
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130902/16a95943/attachment.html>


More information about the cfe-dev mailing list