[clang] d96bf6e - Revert "[clang-format] Adjust braced list detection"

Krasimir Georgiev via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 19 07:05:47 PST 2021


Author: Krasimir Georgiev
Date: 2021-12-19T16:04:42+01:00
New Revision: d96bf6ea461810f7def54541dbcb7ceaecd2d065

URL: https://github.com/llvm/llvm-project/commit/d96bf6ea461810f7def54541dbcb7ceaecd2d065
DIFF: https://github.com/llvm/llvm-project/commit/d96bf6ea461810f7def54541dbcb7ceaecd2d065.diff

LOG: Revert "[clang-format] Adjust braced list detection"

It appears that this regressed the formatting of initializer lists in some
cases, see comments on https://reviews.llvm.org/D114583. I'll follow-up
by adding regression tests for these.

This reverts commit c41b3b0fa0f4f70aad8deaf48bcd42a04385066c.

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D116000

Added: 
    

Modified: 
    clang/lib/Format/UnwrappedLineParser.cpp
    clang/unittests/Format/FormatTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 856efbd91cb01..c34d515a32d65 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -578,14 +578,17 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
           // BlockKind later if we parse a braced list (where all blocks
           // inside are by default braced lists), or when we explicitly detect
           // blocks (for example while parsing lambdas).
+          // FIXME: Some of these do not apply to JS, e.g. "} {" can never be a
+          // braced list in JS.
           ProbablyBracedList =
               (Style.Language == FormatStyle::LK_JavaScript &&
                NextTok->isOneOf(Keywords.kw_of, Keywords.kw_in,
                                 Keywords.kw_as)) ||
               (Style.isCpp() && NextTok->is(tok::l_paren)) ||
               NextTok->isOneOf(tok::comma, tok::period, tok::colon,
-                               tok::r_paren, tok::r_square, tok::ellipsis) ||
-              (NextTok->isOneOf(tok::l_brace, tok::identifier) &&
+                               tok::r_paren, tok::r_square, tok::l_brace,
+                               tok::ellipsis) ||
+              (NextTok->is(tok::identifier) &&
                !PrevTok->isOneOf(tok::semi, tok::r_brace, tok::l_brace)) ||
               (NextTok->is(tok::semi) &&
                (!ExpectClassBody || LBraceStack.size() != 1)) ||
@@ -2861,7 +2864,7 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
       //     class Foo implements {bar: number} { }
       nextToken();
       if (FormatTok->is(tok::l_brace)) {
-        parseBracedList();
+        tryToParseBracedList();
         continue;
       }
     }

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 2a9de85bf453b..d12796e32e577 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -11867,27 +11867,6 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
                "  f(v);\n"
                "}");
 
-  verifyFormat("void foo() {\n"
-               "  { // asdf\n"
-               "    { int a; }\n"
-               "  }\n"
-               "  {\n"
-               "    { int b; }\n"
-               "  }\n"
-               "}");
-  verifyFormat("namespace n {\n"
-               "void foo() {\n"
-               "  {\n"
-               "    {\n"
-               "      statement();\n"
-               "      if (false) {\n"
-               "      }\n"
-               "    }\n"
-               "  }\n"
-               "  {}\n"
-               "}\n"
-               "} // namespace n");
-
   // Long lists should be formatted in columns even if they are nested.
   verifyFormat(
       "vector<int> x = function({1, 22, 333, 4444, 55555, 666666, 7777777,\n"


        


More information about the cfe-commits mailing list