[PATCH] D37980: [clang-format] Better parsing of lambda captures with initializer expressions.

Marek Kurdej via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 18 08:48:30 PDT 2017


curdeius created this revision.

This fixes bug #19986 (https://bugs.llvm.org/show_bug.cgi?id=19986).
The code was incorrectly formatted to (mind additional spaces inside brackets) when lambda capture contained an initializer expression.
This patch does not handle all possible initializers, but the most common once.
To handle these resting cases, we'd have to parse the whole initializer expressions or handle lambda detection differently.

Before:

  int i = 100;
  auto f1 = [ i, value = 23 ]() { return i + value; };
  auto f2 = [ i, value{23} ]() { return i + value; };

After:

  int i = 100;
  auto f1 = [i, value = 23]() { return i + value; };
  auto f2 = [i, value{23}]() { return i + value; };


https://reviews.llvm.org/D37980

Files:
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UnwrappedLineParser.h
  unittests/Format/FormatTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37980.115664.patch
Type: text/x-patch
Size: 8113 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170918/3debd521/attachment.bin>


More information about the cfe-commits mailing list