This is an archive of the discontinued LLVM Phabricator instance.

clang-format: Add support for formatting lambdas with explicit template parameters.
ClosedPublic

Authored by thakis on Sep 5 2019, 5:05 PM.

Diff Detail

Event Timeline

thakis created this revision.Sep 5 2019, 5:05 PM

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.

clang/lib/Format/TokenAnnotator.cpp
44

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]().

50

The first Left->Previous check is unnecessary here, following the previous if.

55

nit: consider replacing with

Check for `[...]`
thakis marked 3 inline comments as done.Sep 10 2019, 12:51 PM

Thanks for the thorough review! Indeed, this still gets []<bool b = true && false>(A &&a){}(); wrong, for the reason you mention.

clang/lib/Format/TokenAnnotator.cpp
50

I removed the previous if, it makes the function more symmetric.

Do you think this should land with the comment FIXME for now? It improves formatting of this language feature when that heuristic is not used, and changing the heuristic is independent of the rest of this patch.

krasimir accepted this revision.Sep 13 2019, 2:07 AM

This looks good with the FIXME.

This revision is now accepted and ready to land.Sep 13 2019, 2:07 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 13 2019, 6:20 AM