[PATCH] D79773: [clang-format] Improve clang-formats handling of concepts

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 20 05:56:06 PDT 2020


MyDeveloperDay marked 7 inline comments as done.
MyDeveloperDay added inline comments.


================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2281
+  if (FormatTok->Tok.is(tok::kw_requires))
+    parseRequires();
+}
----------------
miscco wrote:
> I believe this should be `parseConstraintExpression`  because that is the term of art in the standard.
> 
> The requires expression is what is the `requieres { }` and that can be part of an constraint expression 
I'm making some of these changes, the problem is with the form

`concept id = Foo<T> && Bar<T>`

in this case the 

`Foo<T> && Bar<T>` 

will be processed by the `parseStructualElement()` and this gets confused with the && being a `TT_PointerOrRefernce` and not a `TT_BinaryOperator` and that throws everything out.

I think parseStructualElement() is thinking `Foo<T> &&` is part of

`foo(Foo<T> &&abc);`

and not

`Foo<T> && abc<T>`

We need to know we are in a concept expression




================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2314
+      nextToken();
+      if (FormatTok->Tok.is(tok::less)) {
+        while (!FormatTok->Tok.is(tok::greater)) {
----------------
miscco wrote:
> miscco wrote:
> > I guess you could use `parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,/*ClosingBraceKind=*/tok::greater);` here?
> To be more specific, I am concerned what happens if you have multiple template arguments where a linebreak should occur. Is this still happening here?
> 
> 
> ```
> template <typename someLongTypename1, typename someLongTypename2>
> concept someVeryLongConceptName = someVeryLongConstraintName1<someLongTypename1 && someLongTypename2>;
> ```
This is formatted as

```
template <typename someLongTypename1, typename someLongTypename2>
concept someVeryLongConceptName =
    someVeryLongConstraintName1<someLongTypename1 && someLongTypename2>;
```


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

https://reviews.llvm.org/D79773





More information about the cfe-commits mailing list