diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -1172,8 +1172,12 @@ } if (NextNonComment->is(TT_TemplateString) && NextNonComment->closesScope()) return State.Stack[State.Stack.size() - 2].LastSpace; + // Field labels in a nested type should be aligned to the brace. For example + // in ProtoBuf: + // optional int32 b = 2 [(foo_options) = {aaaaaaaaaaaaaaaaaaa: 123, + // bbbbbbbbbbbbbbbbbbbbbbbb:"baz"}]; if (Current.is(tok::identifier) && Current.Next && - (Current.Next->is(TT_DictLiteral) || + ((Current.Next->is(tok::colon) && Current.Next->is(TT_DictLiteral)) || ((Style.Language == FormatStyle::LK_Proto || Style.Language == FormatStyle::LK_TextProto) && Current.Next->isOneOf(tok::less, tok::l_brace)))) { diff --git a/clang/unittests/Format/FormatTestVerilog.cpp b/clang/unittests/Format/FormatTestVerilog.cpp --- a/clang/unittests/Format/FormatTestVerilog.cpp +++ b/clang/unittests/Format/FormatTestVerilog.cpp @@ -1172,6 +1172,15 @@ verifyFormat("c = '{a : 0, b : 0.0, default : 0};", Style); verifyFormat("c = ab'{a : 0, b : 0.0};", Style); verifyFormat("c = ab'{cd : cd'{1, 1.0}, ef : ef'{2, 2.0}};", Style); + + // It should be indented correctly when the line has to break. + verifyFormat("c = //\n" + " '{default: 0};"); + Style = getDefaultStyle(); + Style.ContinuationIndentWidth = 2; + verifyFormat("c = //\n" + " '{default: 0};", + Style); } TEST_F(FormatTestVerilog, StructuredProcedure) {