Skip to content

Commit

Permalink
[clang-format] Fix SpacesInSquareBrackets for Lambdas with Initial "&…
Browse files Browse the repository at this point in the history
…ref" Parameter

Summary:
This fixes an edge case in the `SpacesInSquareBrackets` option where an initial `&ref` lambda parameter is not padded with an initial space.

`int foo = [&bar ]() {}` is fixed to give `int foo = [ &bar ]() {}`

Reviewers: MyDeveloperDay, klimek, sammccall

Reviewed by: MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D69649
  • Loading branch information
Mitchell Balan committed Oct 31, 2019
1 parent 1725f28 commit 8d7bd57
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Format/TokenAnnotator.cpp
Expand Up @@ -2567,7 +2567,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
return Left.Tok.isLiteral() || (Left.is(tok::identifier) && Left.Previous &&
Left.Previous->is(tok::kw_case));
if (Left.is(tok::l_square) && Right.is(tok::amp))
return false;
return Style.SpacesInSquareBrackets;
if (Right.is(TT_PointerOrReference)) {
if (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) {
if (!Left.MatchingParen)
Expand Down
4 changes: 4 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Expand Up @@ -10572,6 +10572,10 @@ TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {
// Lambdas.
verifyFormat("int c = []() -> int { return 2; }();\n", Spaces);
verifyFormat("return [ i, args... ] {};", Spaces);
verifyFormat("int foo = [ &bar ]() {};", Spaces);
verifyFormat("int foo = [ = ]() {};", Spaces);
verifyFormat("int foo = [ =, &bar ]() {};", Spaces);
verifyFormat("int foo = [ &bar, = ]() {};", Spaces);
}

TEST_F(FormatTest, ConfigurableSpaceBeforeAssignmentOperators) {
Expand Down

0 comments on commit 8d7bd57

Please sign in to comment.