krasimir updated this revision to Diff 90715.
krasimir added a comment.

- Added missing newline


https://reviews.llvm.org/D30659

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


Index: unittests/Format/NamespaceEndCommentsFixerTest.cpp
===================================================================
--- unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ 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,
Index: lib/Format/NamespaceEndCommentsFixer.cpp
===================================================================
--- lib/Format/NamespaceEndCommentsFixer.cpp
+++ 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: unittests/Format/NamespaceEndCommentsFixerTest.cpp
===================================================================
--- unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ 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,
Index: lib/Format/NamespaceEndCommentsFixer.cpp
===================================================================
--- lib/Format/NamespaceEndCommentsFixer.cpp
+++ 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 &&
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to