Skip to content

Commit

Permalink
[clang-format] Fix line parsing for noexcept lambdas
Browse files Browse the repository at this point in the history
Summary:
> $ echo "int c = [b]() mutable noexcept { return [&b] { return b++; }(); }();" |clang-format

```
int c = [b]() mutable noexcept {
  return [&b] { return b++; }();
}
();
```
with patch:
> $ echo "int c = [b]() mutable noexcept { return [&b] { return b++; }(); }();" |bin/clang-format
```
int c = [b]() mutable noexcept { return [&b] { return b++; }(); }();
```

Contributed by hultman.

Reviewers: benhamilton, jolesiak, klimek, Wizard

Reviewed By: benhamilton

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D56909

llvm-svn: 352622
  • Loading branch information
bhamiltoncx committed Jan 30, 2019
1 parent 365021c commit 4e442bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions clang/lib/Format/UnwrappedLineParser.cpp
Expand Up @@ -1422,6 +1422,7 @@ bool UnwrappedLineParser::tryToParseLambda() {
case tok::numeric_constant:
case tok::coloncolon:
case tok::kw_mutable:
case tok::kw_noexcept:
nextToken();
break;
case tok::arrow:
Expand Down
2 changes: 2 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Expand Up @@ -11725,6 +11725,8 @@ TEST_F(FormatTest, FormatsWithWebKitStyle) {

TEST_F(FormatTest, FormatsLambdas) {
verifyFormat("int c = [b]() mutable { return [&b] { return b++; }(); }();\n");
verifyFormat(
"int c = [b]() mutable noexcept { return [&b] { return b++; }(); }();\n");
verifyFormat("int c = [&] { [=] { return b++; }(); }();\n");
verifyFormat("int c = [&, &a, a] { [=, c, &d] { return b++; }(); }();\n");
verifyFormat("int c = [&a, &a, a] { [=, a, b, &c] { return b++; }(); }();\n");
Expand Down

0 comments on commit 4e442bb

Please sign in to comment.