[PATCH] D114521: [clang-format] [PR47936] AfterControlStatement: MultiLine breaks AllowShortFunctionsOnASingleLine

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 24 08:51:37 PST 2021


MyDeveloperDay added a comment.

I think the problem here is encapsulated by adding the following tests

   Style.BraceWrapping.AfterFunction = true;
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
   Style.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_AllIfsAndElse;
   Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Always;
   Style.AllowShortLoopsOnASingleLine = true;
   Style.ColumnLimit = 80;
  
   Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Never;
   verifyFormat("void shortfunction() { bar(); }", Style);
   verifyFormat("if (x) { bar(); }", Style);
   verifyFormat("for (;;) { bar(); }", Style);
   verifyFormat("while (true) { bar(); }", Style);
   Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_MultiLine;
   verifyFormat("void shortfunction() { bar(); }", Style);
   verifyFormat("if (x) { bar(); }", Style);
  >>> FAILS  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  
   verifyFormat("for (;;) { bar(); }", Style);
  >>> FAILS  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  
   verifyFormat("while (true) { bar(); }", Style);
  >>> FAILS  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  
   Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Never;
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
   Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never;
   Style.AllowShortLoopsOnASingleLine = false;
   verifyFormat("void shortfunction()\n"
                "{\n"
                "  foo();\n"
                "}",
                Style);
   verifyFormat("if (x) {\n"
                "  foo();\n"
                "}",
                Style);
   verifyFormat("for (;;) {\n"
                "  foo();\n"
                "}",
                Style);
   verifyFormat("while (true) {\n"
                "  foo();\n"
                "}",
                Style);
  
   Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_MultiLine;
   verifyFormat("void shortfunction()\n"
                "{\n"
                "  foo();\n"
                "}",
                Style);
   verifyFormat("if (x) {\n"
                "  foo();\n"
                "}",
                Style);
   verifyFormat("for (;;) {\n"
                "  foo();\n"
                "}",
                Style);
   verifyFormat("while (true) {\n"
                "  foo();\n"
                "}",
                Style);


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114521/new/

https://reviews.llvm.org/D114521



More information about the cfe-commits mailing list