diff options
-rw-r--r-- | lib/Format/Format.cpp | 2 | ||||
-rw-r--r-- | lib/Format/TokenAnnotator.cpp | 2 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 5 |
3 files changed, 5 insertions, 4 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 03177e586a..471af1d539 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -690,7 +690,7 @@ private: if (I[1]->Last->Type == TT_LineComment) return 0; do { - if (Tok->isOneOf(tok::l_brace, tok::r_brace) && + if (Tok->is(tok::l_brace) && Tok->BlockKind != BK_BracedInit && !Style.AllowShortBlocksOnASingleLine) return 0; Tok = Tok->Next; diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index dca20d2d75..f3d655ace5 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -298,6 +298,8 @@ private: ScopedContextCreator ContextCreator(*this, tok::l_brace, 1); Contexts.back().ColonIsDictLiteral = true; + if (Left->BlockKind == BK_BracedInit) + Contexts.back().IsExpression = true; while (CurrentToken) { if (CurrentToken->is(tok::r_brace)) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 3dbada81f0..af0b5a1cb6 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4694,6 +4694,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyFormat("auto PointerBinding = [](const char *S) {};"); verifyFormat("typedef typeof(int(int, int)) *MyFunc;"); verifyIndependentOfContext("typedef void (*f)(int *a);"); + verifyIndependentOfContext("int i{a * b};"); verifyIndependentOfContext("InvalidRegions[*R] = 0;"); @@ -7044,9 +7045,7 @@ TEST_F(FormatTest, DoNotCreateUnreasonableUnwrappedLines) { TEST_F(FormatTest, DoNotPrematurelyEndUnwrappedLineForReturnStatements) { verifyFormat( - "void f() {\n" - " return C{param1, param2}.SomeCall(param1, param2);\n" - "}\n"); + "void f() { return C{param1, param2}.SomeCall(param1, param2); }"); } TEST_F(FormatTest, FormatsClosingBracesInEmptyNestedBlocks) { |