[PATCH] Replace the broken LambdaCapture::isInitCapture API.

James Dennett jdennett at google.com
Thu Jun 11 22:52:22 PDT 2015


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/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9486.27565.patch
Type: text/x-patch
Size: 903 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150612/129e27d1/attachment.bin>


More information about the cfe-commits mailing list