[PATCH] D113319: [clang-format] Improve require and concept handling

Björn Schäpers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 4 11:00:07 PST 2022


HazardyKnusperkeks marked 15 inline comments as done.
HazardyKnusperkeks added inline comments.


================
Comment at: clang/include/clang/Format/Format.h:3130-3136
+  /// \brief The position of the ``requires`` clause for class templates.
+  /// \version 14
+  RequiresClausePositionStyle RequiresClausePositionForClasses;
+
+  /// \brief The position of the ``requires`` clause for function templates.
+  /// \version 14
+  RequiresClausePositionStyle RequiresClausePositionForFunctions;
----------------
Quuxplusone wrote:
> HazardyKnusperkeks wrote:
> > Quuxplusone wrote:
> > > What about for variable templates? What about for alias templates? What about for deduction guides?
> > > It makes sense to me to have //one// option for this. It doesn't make sense to have 2, 3, or 4. Having 5 feels insane. So, I think you should just have one option that applies consistently to all `requires`-clauses everywhere in the code.
> > That makes sense, in my defense I thought about it and came to the conclusion there would be no need for requires on variable templates, and the others I did not think of.
> > 
> > Why I have chosen to options is maybe someone wants
> > ```template <typename T>
> > requires ...
> > class ...```
> > 
> > But also
> > ```template <typename T>
> > void foo(T) requires ... {
> > ```
> > 
> > What's your opinion on that?
> Well, I see that there is a machine-readable distinction between "`requires` after `template`" versus "`requires` after function parameter list," i.e. between
> ```
> template<class T> requires X
> void f(T);
> 
> template<class T>
> void f(T) requires X;
> ```
> The latter position is not (currently) valid for non-functions (e.g. `template<class T> int v requires X;` is a syntax error).
> However, as usual, I don't think that the user should //want// to format these differently.
> If you're using clang-format to format your code, then you should definitely want function-parameter-list-requires-clauses on their own line for sure, to avoid confusing strings of tokens such as
> ```
> void f() const noexcept requires foobar<T>;  // bad
> 
> void f() const noexcept  // better
>   requires foobar<T>;
> ```
> If you do that, then (in my proposed world) you would also automatically get
> ```
> template<class T>
>   requires foobar<T>  // automatically
> void f();
> 
> template<class T> requires foobar<T>  // can't get this
> void f();
> 
> template<foobar T>  // could also get this, via manual intervention
> void f();
> ```
> And personally I see nothing wrong with that state of affairs.
I still can imagine someone maybe wants it different, but for now I go with your suggestion, only one option for all clauses.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113319/new/

https://reviews.llvm.org/D113319



More information about the cfe-commits mailing list