Skip to content

Commit

Permalink
[clang-format] fix crash in NamespaceEndCommentsFixer (PR32438)
Browse files Browse the repository at this point in the history
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

llvm-svn: 299465
  • Loading branch information
mgehre committed Apr 4, 2017
1 parent 8465d08 commit ddae251
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Format/NamespaceEndCommentsFixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ tooling::Replacements NamespaceEndCommentsFixer::analyze(
// 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)
Expand Down
15 changes: 15 additions & 0 deletions clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ddae251

Please sign in to comment.