r354880 - [clang-format] SpaceBeforeParens for lambda expressions
Andrew Ng via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 26 06:34:49 PST 2019
Author: anng
Date: Tue Feb 26 06:34:49 2019
New Revision: 354880
URL: http://llvm.org/viewvc/llvm-project?rev=354880&view=rev
Log:
[clang-format] SpaceBeforeParens for lambda expressions
Add support for lambda expressions to the SpaceBeforeParens formatting
option.
Differential Revision: https://reviews.llvm.org/D58241
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=354880&r1=354879&r2=354880&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Feb 26 06:34:49 2019
@@ -2547,7 +2547,9 @@ bool TokenAnnotator::spaceRequiredBetwee
(!Left.Previous || Left.Previous->isNot(tok::period))))) ||
(Style.SpaceBeforeParens == FormatStyle::SBPO_Always &&
(Left.is(tok::identifier) || Left.isFunctionLikeKeyword() ||
- Left.is(tok::r_paren)) &&
+ Left.is(tok::r_paren) ||
+ (Left.is(tok::r_square) && Left.MatchingParen &&
+ Left.MatchingParen->is(TT_LambdaLSquare))) &&
Line.Type != LT_PreprocessorDirective);
}
if (Left.is(tok::at) && Right.Tok.getObjCKeywordID() != tok::objc_not_keyword)
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=354880&r1=354879&r2=354880&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Feb 26 06:34:49 2019
@@ -9238,6 +9238,7 @@ TEST_F(FormatTest, ConfigurableSpaceBefo
verifyFormat("typedef void (*cb)(int);", NoSpace);
verifyFormat("T A::operator()();", NoSpace);
verifyFormat("X A::operator++(T);", NoSpace);
+ verifyFormat("auto lambda = []() { return 0; };", NoSpace);
FormatStyle Space = getLLVMStyle();
Space.SpaceBeforeParens = FormatStyle::SBPO_Always;
@@ -9285,6 +9286,7 @@ TEST_F(FormatTest, ConfigurableSpaceBefo
verifyFormat("typedef void (*cb) (int);", Space);
verifyFormat("T A::operator() ();", Space);
verifyFormat("X A::operator++ (T);", Space);
+ verifyFormat("auto lambda = [] () { return 0; };", Space);
}
TEST_F(FormatTest, ConfigurableSpacesInParentheses) {
More information about the cfe-commits
mailing list