diff options
-rw-r--r-- | clang/lib/Format/NamespaceEndCommentsFixer.cpp | 5 | ||||
-rw-r--r-- | clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp | 18 |
2 files changed, 22 insertions, 1 deletions
diff --git a/clang/lib/Format/NamespaceEndCommentsFixer.cpp b/clang/lib/Format/NamespaceEndCommentsFixer.cpp index 578dcf7b670..d0b5919c9bd 100644 --- a/clang/lib/Format/NamespaceEndCommentsFixer.cpp +++ b/clang/lib/Format/NamespaceEndCommentsFixer.cpp @@ -135,7 +135,10 @@ tooling::Replacements NamespaceEndCommentsFixer::analyze( 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 && diff --git a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp index 28212f8524d..0341fd7ef44 100644 --- a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp +++ b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp @@ -388,6 +388,24 @@ TEST_F(NamespaceEndCommentsFixerTest, " 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, |