r299465 - [clang-format] fix crash in NamespaceEndCommentsFixer (PR32438)
Matthias Gehre via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 4 13:11:13 PDT 2017
Author: mgehre
Date: Tue Apr 4 15:11:13 2017
New Revision: 299465
URL: http://llvm.org/viewvc/llvm-project?rev=299465&view=rev
Log:
[clang-format] fix crash in NamespaceEndCommentsFixer (PR32438)
Summary:
The new test case was crashing before. Now it passes
as expected.
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D31441
Modified:
cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp
cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp
Modified: cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp?rev=299465&r1=299464&r2=299465&view=diff
==============================================================================
--- cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp (original)
+++ cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp Tue Apr 4 15:11:13 2017
@@ -133,7 +133,7 @@ tooling::Replacements NamespaceEndCommen
// Detect "(inline)? namespace" in the beginning of a line.
if (NamespaceTok->is(tok::kw_inline))
NamespaceTok = NamespaceTok->getNextNonComment();
- if (NamespaceTok->isNot(tok::kw_namespace))
+ if (!NamespaceTok || NamespaceTok->isNot(tok::kw_namespace))
continue;
FormatToken *RBraceTok = EndLine->First;
if (RBraceTok->Finalized)
Modified: cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp?rev=299465&r1=299464&r2=299465&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp (original)
+++ cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp Tue Apr 4 15:11:13 2017
@@ -582,6 +582,21 @@ TEST_F(NamespaceEndCommentsFixerTest,
"} // namespace\n"
"}"));
}
+
+TEST_F(NamespaceEndCommentsFixerTest, HandlesInlineAtEndOfLine_PR32438) {
+ EXPECT_EQ("template <int> struct a {};\n"
+ "struct a<bool{}> b() {\n"
+ "}\n"
+ "#define c inline\n"
+ "void d() {\n"
+ "}\n",
+ fixNamespaceEndComments("template <int> struct a {};\n"
+ "struct a<bool{}> b() {\n"
+ "}\n"
+ "#define c inline\n"
+ "void d() {\n"
+ "}\n"));
+}
} // end namespace
} // end namespace format
} // end namespace clang
More information about the cfe-commits
mailing list