]> granicus.if.org Git - clang/commitdiff
clang-format: Avoid unnecessary break before lambda return type.
authorDaniel Jasper <djasper@google.com>
Tue, 11 Mar 2014 11:03:26 +0000 (11:03 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 11 Mar 2014 11:03:26 +0000 (11:03 +0000)
Before:
  auto aaaaaaaa = [](int i,  // break
                     int j)
                      -> int {
    return fffffffffffffffffffffffffffffffffffffff(i * j);
  };

After:
  auto aaaaaaaa = [](int i,  // break
                     int j) -> int {
    return fffffffffffffffffffffffffffffffffffffff(i * j);
  };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203562 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTest.cpp

index ed5ce4a21e868b43e4d8ba368a379dd4ef0b5f0c..a96f1680db775a5cc0bb03c31a0e7de2185a9693 100644 (file)
@@ -108,7 +108,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
   //   SomeParameter, OtherParameter).DoSomething(
   //   ...
   // As they hide "DoSomething" and are generally bad for readability.
-  if (Previous.opensScope() && State.LowestLevelOnLine < State.StartOfLineLevel)
+  if (Previous.opensScope() && Previous.isNot(tok::l_brace) &&
+      State.LowestLevelOnLine < State.StartOfLineLevel)
     return false;
   if (Current.isMemberAccess() && State.Stack.back().ContainsUnwrappedBuilder)
     return false;
index c6968bcef9e3b2a42dfbc86584d72aff7604c91b..78aa3ce7c8a4ed1d16f7f1b9813a9a4a60e87ef5 100644 (file)
@@ -7974,6 +7974,10 @@ TEST_F(FormatTest, FormatsLambdas) {
   verifyFormat("int c = []() -> int { return 2; }();\n");
   verifyFormat("int c = []() -> vector<int> { return {2}; }();\n");
   verifyFormat("Foo([]() -> std::vector<int> { return {2}; }());");
+  verifyFormat("auto aaaaaaaa = [](int i, // break for some reason\n"
+               "                   int j) -> int {\n"
+               "  return fffffffffffffffffffffffffffffffffffffff(i * j);\n"
+               "};");
 
   // Not lambdas.
   verifyFormat("constexpr char hello[]{\"hello\"};");