strager created this revision. strager added a reviewer: djasper. strager added subscribers: sas, abdulras, cfe-commits. Herald added a subscriber: klimek.
Teach clang-format about C++14 generalized lambda captures: auto f = [b = std::move(d)]() {}; (clang-format would not think there's a lambda here because of the `=`.) http://reviews.llvm.org/D11693 Files: lib/Format/UnwrappedLineParser.cpp unittests/Format/FormatTest.cpp Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -9981,6 +9981,11 @@ // More complex introducers. verifyFormat("return [i, args...] {};"); + // Lambdas with generalized captures. + verifyFormat("auto f = [b = d]() {};\n"); + verifyFormat("auto f = [b = std::move(d)]() {};\n"); + verifyFormat("auto f = [b = c, d = e, g]() {};\n"); + // Not lambdas. verifyFormat("constexpr char hello[]{\"hello\"};"); verifyFormat("double &operator[](int i) { return 0; }\n" Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -1051,6 +1051,20 @@ nextToken(); if (FormatTok->is(tok::ellipsis)) nextToken(); + if (FormatTok->is(tok::equal)) { + nextToken(); + while (!eof()) { + // FIXME: Once we have an expression parser in the UnwrappedLineParser, + // replace this by using parseAssigmentExpression() inside. + if (FormatTok->is(tok::l_paren)) { + parseParens(); + } else if (FormatTok->isOneOf(tok::comma, tok::r_square)) { + break; + } else { + nextToken(); + } + } + } if (FormatTok->is(tok::comma)) { nextToken(); } else if (FormatTok->is(tok::r_square)) {
Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -9981,6 +9981,11 @@ // More complex introducers. verifyFormat("return [i, args...] {};"); + // Lambdas with generalized captures. + verifyFormat("auto f = [b = d]() {};\n"); + verifyFormat("auto f = [b = std::move(d)]() {};\n"); + verifyFormat("auto f = [b = c, d = e, g]() {};\n"); + // Not lambdas. verifyFormat("constexpr char hello[]{\"hello\"};"); verifyFormat("double &operator[](int i) { return 0; }\n" Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -1051,6 +1051,20 @@ nextToken(); if (FormatTok->is(tok::ellipsis)) nextToken(); + if (FormatTok->is(tok::equal)) { + nextToken(); + while (!eof()) { + // FIXME: Once we have an expression parser in the UnwrappedLineParser, + // replace this by using parseAssigmentExpression() inside. + if (FormatTok->is(tok::l_paren)) { + parseParens(); + } else if (FormatTok->isOneOf(tok::comma, tok::r_square)) { + break; + } else { + nextToken(); + } + } + } if (FormatTok->is(tok::comma)) { nextToken(); } else if (FormatTok->is(tok::r_square)) {
_______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits