[PATCH] D67246: clang-format: Add support for formatting lambdas with explicit template parameters.

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 10 02:32:06 PDT 2019


krasimir added a comment.

I'll need some more time to investigate the implications of this with respect to Objective-C disambiguation stuff. 
Specifically, this may interact with funny ways with the heuristic outlined in (old) UnwrappedLineParser.cpp line 1453:

  // In a C++ lambda a template type can only occur after an arrow. We use
  // this as an heuristic to distinguish between Objective-C expressions
  // followed by an `a->b` expression, such as:
  // ([obj func:arg] + a->b)

At least we'll have to update this comment accordingly, otherwise it will be confusing.



================
Comment at: clang/lib/Format/TokenAnnotator.cpp:44
+/// With `Left` being '(', check if we're at either `[...](` or
+/// `...]<...>(`.
+static bool isLambdaParameterList(const FormatToken *Left) {
----------------
nit: add a `[` in the second case, like `[...]<...>(`. Also I'd suggest extending this sentence with: ", where the `[` opens a lambda capture list", because we explicitly check the `[` for that and to disambiguate between the case this is interested in and Objective-C method calls followed by function-invocation style call, like in `[obj meth]()`.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:50
+  // Skip <...> if present.
+  if (Left->Previous && Left->Previous->is(tok::greater) &&
+      Left->Previous->MatchingParen &&
----------------
The first `Left->Previous` check is unnecessary here, following the previous `if`.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:55
+
+  // Check for `[...](`.
+  return Left->Previous && Left->Previous->is(tok::r_square) &&
----------------
nit: consider replacing with 
```
Check for `[...]`
```


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

https://reviews.llvm.org/D67246





More information about the cfe-commits mailing list