[PATCH] D42684: clang-format: Allow optimizer to break template declaration.

Francois Ferrand via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 28 07:05:01 PST 2018


Typz added a comment.

In https://reviews.llvm.org/D42684#1013005, @djasper wrote:

> Please given an explanation of what you are trying to achieve with this change. Do you intend to set the penalty high so that clang-format does other things first before falling back to wrapping template declarations?
>
> Why treat separate declarations differently wrt. wrapping the template declarations? Will this stop at classes vs. functions? I generally have doubts that this option carries it's weight. Do you have a style guide that explicitly tells you to do this?


I set the penalty relatively high (200), i.e. the same penalty that I have set for `PenaltyBreakAssignment`, `PenaltyBreakBeforeFirstCallParameter`, and `PenaltyReturnTypeOnItsOwnLine`.
Basically we don't have a preference as to where the break should be, and we found that setting the same penalty for all these parameters (including the new `PenaltyBreakTemplateDeclaration`) gives really "natural" result: e.g. very close to how a user would optimize the code wrapping for readability.

At the moment `AlwaysBreakTemplateDeclarations` actually applies only to classes, thus templates are always wrapped before functions (unless it all fits on one line). A simpler change would have been to make `AlwaysBreakTemplateDeclarations` stick to its name, and let it apply to functions as well: but I figured with would break existing clang-format styles.


Repository:
  rC Clang

https://reviews.llvm.org/D42684





More information about the cfe-commits mailing list