mgehre created this revision. Herald added a subscriber: klimek. The new test case was crashing before. Now it passes as expected.
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, 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 @@ -131,8 +131,11 @@ assert(StartLineIndex < E); const FormatToken *NamespaceTok = AnnotatedLines[StartLineIndex]->First; // Detect "(inline)? namespace" in the beginning of a line. - if (NamespaceTok->is(tok::kw_inline)) + if (NamespaceTok->is(tok::kw_inline)) { NamespaceTok = NamespaceTok->getNextNonComment(); + if (!NamespaceTok) + continue; + } if (NamespaceTok->isNot(tok::kw_namespace)) continue; FormatToken *RBraceTok = EndLine->First;
Index: unittests/Format/NamespaceEndCommentsFixerTest.cpp =================================================================== --- unittests/Format/NamespaceEndCommentsFixerTest.cpp +++ unittests/Format/NamespaceEndCommentsFixerTest.cpp @@ -582,6 +582,21 @@ "} // namespace\n" "}")); } + +TEST_F(NamespaceEndCommentsFixerTest, 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 @@ -131,8 +131,11 @@ assert(StartLineIndex < E); const FormatToken *NamespaceTok = AnnotatedLines[StartLineIndex]->First; // Detect "(inline)? namespace" in the beginning of a line. - if (NamespaceTok->is(tok::kw_inline)) + if (NamespaceTok->is(tok::kw_inline)) { NamespaceTok = NamespaceTok->getNextNonComment(); + if (!NamespaceTok) + continue; + } if (NamespaceTok->isNot(tok::kw_namespace)) continue; FormatToken *RBraceTok = EndLine->First;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits