[PATCH] D31441: [clang-format] fix crash in NamespaceEndCommentsFixer (PR32438)
Matthias Gehre via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 30 11:10:39 PDT 2017
mgehre updated this revision to Diff 93507.
mgehre added a comment.
Updated for comments
https://reviews.llvm.org/D31441
Files:
lib/Format/NamespaceEndCommentsFixer.cpp
unittests/Format/NamespaceEndCommentsFixerTest.cpp
Index: unittests/Format/NamespaceEndCommentsFixerTest.cpp
===================================================================
--- unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -582,6 +582,21 @@
"} // 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
Index: lib/Format/NamespaceEndCommentsFixer.cpp
===================================================================
--- lib/Format/NamespaceEndCommentsFixer.cpp
+++ lib/Format/NamespaceEndCommentsFixer.cpp
@@ -133,7 +133,7 @@
// 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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31441.93507.patch
Type: text/x-patch
Size: 1631 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170330/3bac07a1/attachment.bin>
More information about the cfe-commits
mailing list