This revision was automatically updated to reflect the committed changes. Closed by commit rL299465: [clang-format] fix crash in NamespaceEndCommentsFixer (PR32438) (authored by mgehre).
Changed prior to commit: https://reviews.llvm.org/D31441?vs=93507&id=94108#toc Repository: rL LLVM https://reviews.llvm.org/D31441 Files: cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp Index: cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp =================================================================== --- cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp +++ cfe/trunk/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) Index: cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp =================================================================== --- cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp +++ cfe/trunk/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: cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp =================================================================== --- cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp +++ cfe/trunk/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) Index: cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp =================================================================== --- cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp +++ cfe/trunk/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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits