Improve formatting of lambda functions.
Don't let the trailing '*' of a lambda's explicitly-specified return
type be immediately adjacent to the left brace that starts the body
of the lambda.
http://reviews.llvm.org/D9486
Files:
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1995,6 +1995,11 @@
return false;
if (Left.is(TT_RegexLiteral))
return false;
+
+ // `[]() -> T *{` needs a space inserted before the left brace.
+ if (Left.is(TT_PointerOrReference) && Right.is(tok::l_brace))
+ return true;
+
return spaceRequiredBetween(Line, Left, Right);
}
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -10581,5 +10581,9 @@
verifyNoCrash("#define a\\\n /**/}");
}
+TEST_F(FormatTest, IncludeSpaceBeforeLambdaBody) {
+ verifyFormat("int *p = []() -> int * { return nullptr; }();");
+}
+
} // end namespace tooling
} // end namespace clang
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1995,6 +1995,11 @@
return false;
if (Left.is(TT_RegexLiteral))
return false;
+
+ // `[]() -> T *{` needs a space inserted before the left brace.
+ if (Left.is(TT_PointerOrReference) && Right.is(tok::l_brace))
+ return true;
+
return spaceRequiredBetween(Line, Left, Right);
}
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -10581,5 +10581,9 @@
verifyNoCrash("#define a\\\n /**/}");
}
+TEST_F(FormatTest, IncludeSpaceBeforeLambdaBody) {
+ verifyFormat("int *p = []() -> int * { return nullptr; }();");
+}
+
} // end namespace tooling
} // end namespace clang
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits