From: Krasimir Georgiev Date: Wed, 1 Mar 2017 16:38:08 +0000 (+0000) Subject: [clang-format] Don't add namespace end comments for unbalanced right braces after... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a3101dbac2a5eac07a9d844bc19d0a0e5bdafd45;p=clang [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 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 9efb681267..6590f38bda 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -2048,6 +2048,7 @@ void UnwrappedLineParser::addUnwrappedLine() { }); CurrentLines->push_back(std::move(*Line)); Line->Tokens.clear(); + Line->MatchingOpeningBlockLineIndex = UnwrappedLine::kInvalidIndex; if (CurrentLines == &Lines && !PreprocessorDirectives.empty()) { CurrentLines->append( std::make_move_iterator(PreprocessorDirectives.begin()), diff --git a/unittests/Format/NamespaceEndCommentsFixerTest.cpp b/unittests/Format/NamespaceEndCommentsFixerTest.cpp index 09f21929c3..c24894e7d4 100644 --- a/unittests/Format/NamespaceEndCommentsFixerTest.cpp +++ b/unittests/Format/NamespaceEndCommentsFixerTest.cpp @@ -345,6 +345,18 @@ TEST_F(NamespaceEndCommentsFixerTest, "}\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 format } // end namespace clang