This revision was automatically updated to reflect the committed changes. Closed by commit rGc8603db0711e: [clang-format] Fix a bug that misformats Access Specifier after *[] (authored by owenpan).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D124589/new/ https://reviews.llvm.org/D124589 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 @@ -3336,6 +3336,14 @@ verifyFormat("if (public == private)\n"); verifyFormat("void foo(public, private)"); verifyFormat("public::foo();"); + + verifyFormat("class A {\n" + "public:\n" + " std::unique_ptr<int *[]> b() { return nullptr; }\n" + "\n" + "private:\n" + " int c;\n" + "};"); } TEST_F(FormatTest, SeparatesLogicalBlocks) { @@ -21487,6 +21495,7 @@ " bar([]() {} // Did not respect SpacesBeforeTrailingComments\n" " );\n" "}"); + verifyFormat("auto k = *[](int *j) { return j; }(&i);"); // Lambdas created through weird macros. verifyFormat("void f() {\n" Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2048,6 +2048,11 @@ nextToken(); if (FormatTok->is(tok::l_square)) return false; + if (FormatTok->is(tok::r_square)) { + const FormatToken *Next = Tokens->peekNextToken(); + if (Next && Next->is(tok::greater)) + return false; + } parseSquare(/*LambdaIntroducer=*/true); return true; }
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -3336,6 +3336,14 @@ verifyFormat("if (public == private)\n"); verifyFormat("void foo(public, private)"); verifyFormat("public::foo();"); + + verifyFormat("class A {\n" + "public:\n" + " std::unique_ptr<int *[]> b() { return nullptr; }\n" + "\n" + "private:\n" + " int c;\n" + "};"); } TEST_F(FormatTest, SeparatesLogicalBlocks) { @@ -21487,6 +21495,7 @@ " bar([]() {} // Did not respect SpacesBeforeTrailingComments\n" " );\n" "}"); + verifyFormat("auto k = *[](int *j) { return j; }(&i);"); // Lambdas created through weird macros. verifyFormat("void f() {\n" Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2048,6 +2048,11 @@ nextToken(); if (FormatTok->is(tok::l_square)) return false; + if (FormatTok->is(tok::r_square)) { + const FormatToken *Next = Tokens->peekNextToken(); + if (Next && Next->is(tok::greater)) + return false; + } parseSquare(/*LambdaIntroducer=*/true); return true; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits