Эх сурвалжийг харах

[clang-format] Don't add namespace end comments for unbalanced right braces after namespace end

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@296638 91177308-0d34-0410-b5e6-96231b3b80d8
Krasimir Georgiev 8 жил өмнө
parent
commit
a3101dbac2

+ 1 - 0
lib/Format/UnwrappedLineParser.cpp

@@ -2048,6 +2048,7 @@ void UnwrappedLineParser::addUnwrappedLine() {
   });
   });
   CurrentLines->push_back(std::move(*Line));
   CurrentLines->push_back(std::move(*Line));
   Line->Tokens.clear();
   Line->Tokens.clear();
+  Line->MatchingOpeningBlockLineIndex = UnwrappedLine::kInvalidIndex;
   if (CurrentLines == &Lines && !PreprocessorDirectives.empty()) {
   if (CurrentLines == &Lines && !PreprocessorDirectives.empty()) {
     CurrentLines->append(
     CurrentLines->append(
         std::make_move_iterator(PreprocessorDirectives.begin()),
         std::make_move_iterator(PreprocessorDirectives.begin()),

+ 12 - 0
unittests/Format/NamespaceEndCommentsFixerTest.cpp

@@ -345,6 +345,18 @@ TEST_F(NamespaceEndCommentsFixerTest,
                                     "}\n"
                                     "}\n"
                                     "}\n"));
                                     "}\n"));
 }
 }
+
+TEST_F(NamespaceEndCommentsFixerTest,
+       DoesNotAddEndCommentForUnbalancedRBracesAfterNamespaceEnd) {
+  EXPECT_EQ("namespace {\n"
+            "  int i;\n"
+            "} // namespace\n"
+            "}",
+            fixNamespaceEndComments("namespace {\n"
+                                    "  int i;\n"
+                                    "} // namespace\n"
+                                    "}"));
+}
 } // end namespace
 } // end namespace
 } // end namespace format
 } // end namespace format
 } // end namespace clang
 } // end namespace clang