diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 102504182c450..ce6c17c3b7d92 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -703,7 +703,9 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, if (Current.is(tok::equal) && (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) && - CurrentState.VariablePos == 0) { + CurrentState.VariablePos == 0 && + (!Previous.Previous || + Previous.Previous->isNot(TT_DesignatedInitializerPeriod))) { CurrentState.VariablePos = State.Column; // Move over * and & if they are bound to the variable name. const FormatToken *Tok = &Previous; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 25ef5c680af86..01678a4971caa 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -4944,6 +4944,18 @@ TEST_F(FormatTest, DesignatedInitializers) { " [3] = cccccccccccccccccccccccccccccccccccccc,\n" " [4] = dddddddddddddddddddddddddddddddddddddd,\n" " [5] = eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee};"); + + verifyFormat("for (const TestCase &test_case : {\n" + " TestCase{\n" + " .a = 1,\n" + " .b = 1,\n" + " },\n" + " TestCase{\n" + " .a = 2,\n" + " .b = 2,\n" + " },\n" + " }) {\n" + "}\n"); } TEST_F(FormatTest, BracedInitializerIndentWidth) {