Commit eb682b80 authored by Jonathan Coe's avatar Jonathan Coe
Browse files

[clang-format] C# does not indent braced initializers as continuations

Summary: C# treats object initializers as braced init blocks. Braced init blocks are no longer indented as continuations.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75731
parent 63b683a8
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -509,6 +509,9 @@ struct FormatToken {
  /// Returns \c true if this tokens starts a block-type list, i.e. a
  /// list that should be indented with a block indent.
  bool opensBlockOrBlockTypeList(const FormatStyle &Style) const {
    // C# Does not indent object initialisers as continuations.
    if (is(tok::l_brace) && BlockKind == BK_BracedInit && Style.isCSharp())
      return true;
    if (is(TT_TemplateString) && opensScope())
      return true;
    return is(TT_ArrayInitializerLSquare) || is(TT_ProtoExtensionLSquare) ||
+4 −1
Original line number Diff line number Diff line
@@ -1677,6 +1677,9 @@ bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons,
      }
      break;
    case tok::l_square:
      if (Style.isCSharp())
        parseSquare();
      else
        tryToParseLambda();
      break;
    case tok::l_paren:
+11 −14
Original line number Diff line number Diff line
@@ -541,10 +541,7 @@ Shape[] shapes = new[] {
  // Omitted final `,`s will change the formatting.
  verifyFormat(R"(//
Shape[] shapes = new[] { new Circle { Radius = 2.7281, Colour = Colours.Red },
                         new Square {
                             Side = 101.1,
                             Colour = Colours.Yellow,
                         } };)",
                         new Square { Side = 101.1, Colour = Colours.Yellow } };)",
               Style);

  // Lambdas can be supplied as initialiser arguments.