-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-format] Ability to configure breaking after short return types #78010
Comments
It isn't exactly clear the best way that this behaviour could be configured. While investigating this, I experimented with an option to configure the column limit to mark the short return type. I made a pull request (#78011) with the result of this work for consideration. |
Should we use a field called ShortTypes where users could define the types they want |
Do you mean an option where you would list all the types you want to be affected by the short type behaviour? The main consideration would be whether it would cause a formatting change when upgrading to the new version. Also, if changing previous formatting, having it be based on the type itself rather than the column would make things clearer.
Though, I wonder whether it could be frustrating if someone wanted it to apply to all types under a certain length. I.e. having to manually add lots of types to the list. |
That's likely a bug. IMO we should fix the bug and optionally add a new boolean value to |
Yeah, the fact that the short return type is based on the column and not the type itself is strange and could be a bug. Though I wouldn't say that just changing it to use the type length would completely solve the issue. Hence how I ended up at a possible solution which enables the functionality to be effectively disabled. |
IMO the bug is not that it doesn't use the length of the type. Instead, the issue is that the (absolute) column position is not adjusted for any indentation. So using the offset relative to the starting column position of the line should be enough to fix the problem. |
I agree with that. With regards to the different states, should it be another enum for |
How about adding a new |
I'm just wondering whether that would suggest that it would always break short return types, rather than the opposite of allowing to break after short return types. |
You are right! I think |
Right. I will look into reworking the PR to use |
PR has now been updated with this new approach. |
…eakAfterReturnType. (#78011) The RTBS_None option in Clang-format avoids breaking after a short return type. However, there was an issue with the behaviour in that it wouldn't take the leading indentation of the line into account. This meant that the behaviour wasn't applying when intended. In order to address this situation without breaking the existing formatting, RTBS_None has been deprecated. In its place are two new options for AlwaysBreakAfterReturnType. The option RTBS_Automatic will break after the return type based on PenaltyReturnTypeOnItsOwnLine. The option RTBS_ExceptShortType will take the leading indentation into account and prevent breaking after short return types. This allows the inconsistent behaviour of RTBS_None to be avoided and users to decide whether they want to allow breaking after short return types or not. Resolves #78010
@owenca, now that the change is in, do you want me to look at renaming |
…eakAfterReturnType. (llvm#78011) The RTBS_None option in Clang-format avoids breaking after a short return type. However, there was an issue with the behaviour in that it wouldn't take the leading indentation of the line into account. This meant that the behaviour wasn't applying when intended. In order to address this situation without breaking the existing formatting, RTBS_None has been deprecated. In its place are two new options for AlwaysBreakAfterReturnType. The option RTBS_Automatic will break after the return type based on PenaltyReturnTypeOnItsOwnLine. The option RTBS_ExceptShortType will take the leading indentation into account and prevent breaking after short return types. This allows the inconsistent behaviour of RTBS_None to be avoided and users to decide whether they want to allow breaking after short return types or not. Resolves llvm#78010
Yep. Thanks! |
Changes the option to BreakAfterReturnType option, with a more relevant name, deprecating and replacing AlwaysBreakAfterReturnType. Following up on #78010.
Currently, when
AlwaysBreakAfterReturnType
isNone
, line breaks are prevented after 'short' return types.From
ContinuationIndenter.cpp
Note, that 'short' here isn't the length of the type itself, but the column where the type finishes.
So, the indentation can change the behaviour.
While the comment says that breaking would be unexpected, this behaviour takes precedence over any of the penalty options for configuring where to place line breaks. It is fairly specific behaviour and can also be unexpected as it avoids breaking after the return type seemly ignoring the penalty configuration.
It would be helpful if there was a way that this could be configured.
The text was updated successfully, but these errors were encountered: