[PATCH] D75410: [Clang-Format] Fixed BraceWrapping.AfterExternBlock

Marcus Johnson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 29 13:55:57 PST 2020


MarcusJohnson91 updated this revision to Diff 247462.
MarcusJohnson91 added a comment.

Rewrote the AfterExternBlock code to rely on just that clang-format option and remove the ExternNamespace check.

Fixed the tests as well.

and clang-formatted everything


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

https://reviews.llvm.org/D75410

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


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2462,14 +2462,18 @@
 
   Style.BraceWrapping.AfterExternBlock = true;
   Style.BraceWrapping.SplitEmptyRecord = false;
-  verifyFormat("extern \"C\"\n"
-               "{}",
-               Style);
-  verifyFormat("extern \"C\"\n"
-               "{\n"
+  verifyFormat("extern \"C\" {}", Style);
+  verifyFormat("extern \"C\" {\n"
                "  int foo();\n"
                "}",
                Style);
+
+  Style.BraceWrapping.AfterExternBlock = false;
+  verifyFormat("extern \"C\" {}", Style);
+  verifyFormat("extern \"C\" {\n"
+               "int foo();\n"
+               "}",
+               Style);
 }
 
 TEST_F(FormatTest, FormatsInlineASM) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1085,13 +1085,8 @@
     if (FormatTok->Tok.is(tok::string_literal)) {
       nextToken();
       if (FormatTok->Tok.is(tok::l_brace)) {
-        if (Style.BraceWrapping.AfterExternBlock &&
-            Style.BraceWrapping.AfterNamespace) {
-          addUnwrappedLine();
+        if (Style.BraceWrapping.AfterExternBlock) {
           parseBlock(/*MustBeDeclaration=*/true);
-        } else if (Style.BraceWrapping.AfterExternBlock &&
-                   Style.BraceWrapping.AfterNamespace == false) {
-          parseBlock(/*MustBeDeclaration=*/false);
         } else {
           parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
         }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75410.247462.patch
Type: text/x-patch
Size: 1724 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200229/b1407988/attachment.bin>


More information about the cfe-commits mailing list