From: Ben Hamilton Date: Wed, 30 Jan 2019 13:54:32 +0000 (+0000) Subject: [clang-format] Fix line parsing for noexcept lambdas X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=39357444223934413e9fbe91902f2ad59516a257;p=clang [clang-format] Fix line parsing for noexcept lambdas 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352622 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 636e2e1c57..f6727fcfa9 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -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: diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 0f7e0cd5b2..99b2beadc4 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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");