owenpan created this revision. owenpan added reviewers: MyDeveloperDay, HazardyKnusperkeks, rymiel. owenpan added a project: clang-format. Herald added a project: All. owenpan requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
To prevent potential bugs in situations where we want to peek the next //non-comment// token. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D142412 Files: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -3444,6 +3444,13 @@ "\n" "private:\n" " int c;\n" + "};\n" + "class B {\n" + "public:\n" + " std::unique_ptr<int *[] /* okay */> b() { return nullptr; }\n" + "\n" + "private:\n" + " int c;\n" "};"); } @@ -9637,6 +9644,19 @@ " return a;\n" "}", Style); + verifyFormat("byte *\n" + "f(a)\n" + "byte /* K&R C */ a[];\n" + "{\n" + " return a;\n" + "}\n" + "byte *\n" + "g(p)\n" + "byte /* K&R C */ *p;\n" + "{\n" + " return p;\n" + "}", + Style); verifyFormat("bool f(int a, int) override;\n" "Bar g(int a, Bar) final;\n" "Bar h(a, Bar) final;", Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -1906,7 +1906,9 @@ // declaration. if (!IsTopLevel || !Style.isCpp() || !Previous || eof()) break; - if (isC78ParameterDecl(FormatTok, Tokens->peekNextToken(), Previous)) { + if (isC78ParameterDecl(FormatTok, + Tokens->peekNextToken(/*SkipComment=*/true), + Previous)) { addUnwrappedLine(); return; } @@ -2376,7 +2378,7 @@ if (FormatTok->is(tok::l_square)) return false; if (FormatTok->is(tok::r_square)) { - const FormatToken *Next = Tokens->peekNextToken(); + const FormatToken *Next = Tokens->peekNextToken(/*SkipComment=*/true); if (Next->is(tok::greater)) return false; }
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -3444,6 +3444,13 @@ "\n" "private:\n" " int c;\n" + "};\n" + "class B {\n" + "public:\n" + " std::unique_ptr<int *[] /* okay */> b() { return nullptr; }\n" + "\n" + "private:\n" + " int c;\n" "};"); } @@ -9637,6 +9644,19 @@ " return a;\n" "}", Style); + verifyFormat("byte *\n" + "f(a)\n" + "byte /* K&R C */ a[];\n" + "{\n" + " return a;\n" + "}\n" + "byte *\n" + "g(p)\n" + "byte /* K&R C */ *p;\n" + "{\n" + " return p;\n" + "}", + Style); verifyFormat("bool f(int a, int) override;\n" "Bar g(int a, Bar) final;\n" "Bar h(a, Bar) final;", Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -1906,7 +1906,9 @@ // declaration. if (!IsTopLevel || !Style.isCpp() || !Previous || eof()) break; - if (isC78ParameterDecl(FormatTok, Tokens->peekNextToken(), Previous)) { + if (isC78ParameterDecl(FormatTok, + Tokens->peekNextToken(/*SkipComment=*/true), + Previous)) { addUnwrappedLine(); return; } @@ -2376,7 +2378,7 @@ if (FormatTok->is(tok::l_square)) return false; if (FormatTok->is(tok::r_square)) { - const FormatToken *Next = Tokens->peekNextToken(); + const FormatToken *Next = Tokens->peekNextToken(/*SkipComment=*/true); if (Next->is(tok::greater)) return false; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits