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

Daniel Jasper via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 28 07:52:12 PST 2018


djasper added a comment.

In https://reviews.llvm.org/D42684#1022093, @Typz wrote:

> The problem I have is really related to the current `AlwaysBreakTemplateDeclarations` behavior, which does not apply to functions.
>  I set it to false, and I get this:
>
>   template<>
>   void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
>       const bbbbbbbbbbbbbbbbbbb & cccccccccc);
>   
>
> instead of:
>
>   template<> void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
>       const bbbbbbbbbbbbbbbbbbb & cccccccccc);
>   
>
> Then when this is fixed the penalty for breaking after the templates part is hardcoded to 10 (`prec::Level::Relational`), which was not always wrapping as expected (that is definitely subjective, but that is the beauty of penalties...)


Ah, I see. However, you are misunderstanding what the parameter is meant to do (and I think what the name says). It is controlling whether we "always" break before the template declaration (even if everything would fit on just one line). Setting it to false, i.e. "not always" breaking, does not imply that there is any particular situation in which we need to keep it on the same line.

I understand what you want to achieve, but I don't think it is related to whether this is a function or a class declaration, i.e. clang-format also does:

  template <typename T>
  class AAAAAAAAAAAAAAAAAAAAAAAAAAAA
      : BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB {};

although the template declaration would easily fit on the same line.

So this change does not seem like the right one to make in order to get the options to be more intuitive and for you to get the behavior you want. I'll try to think about how to achieve that. Do you have any ideas?


Repository:
  rC Clang

https://reviews.llvm.org/D42684





More information about the cfe-commits mailing list