summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-04-09 12:21:48 +0000
committerDaniel Jasper <djasper@google.com>2014-04-09 12:21:48 +0000
commit21397a3232a12804a46f6e59fd83221a4409fbf1 (patch)
treea71d0d025151fd9b76dd51dff40b80a59345079f
parent3ae6f5a47b22a2d7ad4a70438bf143ada09a0ea3 (diff)
downloadbcm5719-llvm-21397a3232a12804a46f6e59fd83221a4409fbf1.tar.gz
bcm5719-llvm-21397a3232a12804a46f6e59fd83221a4409fbf1.zip
clang-format: Fix bug where clang-format would break the code.
Before, it would turn: SomeFunction([]() { // Cool function.. return 43; }); Into this: SomeFunction([]() { // Cool function.. return 43; }); llvm-svn: 205849
-rw-r--r--clang/lib/Format/Format.cpp4
-rw-r--r--clang/unittests/Format/FormatTest.cpp3
2 files changed, 7 insertions, 0 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 5367106535d..4075ccdc8cf 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1121,6 +1121,10 @@ private:
if (Previous.Children.size() > 1)
return false;
+ // Cannot merge into one line if this line ends on a comment.
+ if (Previous.is(tok::comment))
+ return false;
+
// We can't put the closing "}" on a line with a trailing comment.
if (Previous.Children[0]->Last->isTrailingComment())
return false;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index b932b274d70..5f44c5bb2b5 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8161,6 +8161,9 @@ TEST_F(FormatTest, FormatsLambdas) {
" x.end(), //\n"
" [&](int, int) { return 1; });\n"
"}\n");
+ verifyFormat("SomeFunction([]() { // A cool function...\n"
+ " return 43;\n"
+ "});");
// Lambdas with return types.
verifyFormat("int c = []() -> int { return 2; }();\n");
OpenPOWER on IntegriCloud