Hi all,
Hope this is the right channel for this question :). I'm looking at possibly using clang-format to clean up an indentation / formatting style mess for a fairly large project (Apache Traffic Server). One of our "quirks" is that we currently format our functions like:
inline const char*
some_func(int some_arg)
{
…
}
I've tried both
PenaltyReturnTypeOnItsOwnLine: 0
and
PenaltyReturnTypeOnItsOwnLine: 10000
and various numbers in between, but it always formats the above like
inline const char* some_func(int some_arg)
{
…
}
Maybe I'm misunderstanding what PenaltyReturnTypeOnItsOwnLine does? What's even more confusing is that if I use the "mozilla" predefined format, it still doesn't format it like I expect. And I'm 99% certain that Mozilla code also uses the "return type on its own line" formatting.
Cheers!
-- leif
Hi all,
Hope this is the right channel for this question :). I’m looking at possibly using clang-format to clean up an indentation / formatting style mess for a fairly large project (Apache Traffic Server). One of our “quirks” is that we currently format our functions like:
inline const char*
some_func(int some_arg)
{
…
}
I’ve tried both
PenaltyReturnTypeOnItsOwnLine: 0
and
PenaltyReturnTypeOnItsOwnLine: 10000
and various numbers in between, but it always formats the above like
inline const char* some_func(int some_arg)
{
…
}
Maybe I’m misunderstanding what PenaltyReturnTypeOnItsOwnLine does?
I assume it identifies the 'cost of splitting a line after the return. Relative costs of different splits are used in comparisons to decide on the optimal split - I doubt it’ll change anything related to the behavior of the unsplit lines.
Yes, clang-format currently does not have an option that says “always break after a function’s return type”. It should be fairly easy to add, though. Does your coding style prescribe this for definitions only or also for declarations?
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.
Cheers,
-- Leif
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? Is this a feature that a mere mortal (like me…) could contribute?
Cheers,
-- Leif
>
>> 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,