[PATCH] D30659: [clang-format] Make NamespaceEndCommentFixer add at most one comment

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 6 08:56:43 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL297028: [clang-format] Make NamespaceEndCommentFixer add at most one comment (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D30659?vs=90715&id=90716#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30659

Files:
  cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp
  cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp


Index: cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp
===================================================================
--- cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp
+++ cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp
@@ -135,7 +135,10 @@
       NamespaceTok = NamespaceTok->getNextNonComment();
     if (NamespaceTok->isNot(tok::kw_namespace))
       continue;
-    const FormatToken *RBraceTok = EndLine->First;
+    FormatToken *RBraceTok = EndLine->First;
+    if (RBraceTok->Finalized)
+      continue;
+    RBraceTok->Finalized = true;
     const std::string NamespaceName = computeName(NamespaceTok);
     bool AddNewline = (I + 1 < E) &&
                       AnnotatedLines[I + 1]->First->NewlinesBefore == 0 &&
Index: cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp
===================================================================
--- cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -388,6 +388,24 @@
                                     "  int i;\n"
                                     "}\n"
                                     "}\n"));
+  EXPECT_EQ("namespace {\n"
+            "  int i;\n"
+            "  int j;\n"
+            "}// namespace\n"
+            "#if A\n"
+            "  int i;\n"
+            "#else\n"
+            "  int j;\n"
+            "#endif",
+            fixNamespaceEndComments("namespace {\n"
+                                    "  int i;\n"
+                                    "  int j;\n"
+                                    "}\n"
+                                    "#if A\n"
+                                    "  int i;\n"
+                                    "#else\n"
+                                    "  int j;\n"
+                                    "#endif"));
 }
 
 TEST_F(NamespaceEndCommentsFixerTest,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30659.90716.patch
Type: text/x-patch
Size: 1882 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170306/e9dab508/attachment.bin>


More information about the cfe-commits mailing list