Page MenuHomePhabricator

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

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

Diff Detail

Event Timeline

thakis created this revision.Thu, Sep 5, 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.Tue, Sep 10, 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.Fri, Sep 13, 2:07 AM

This looks good with the FIXME.

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