MyDeveloperDay updated this revision to Diff 264325. MyDeveloperDay added a comment.
pre-merge tests showed I wasn't quite rebased however it overlaps with D79354: [clang-format] [PR34574] Handle [[nodiscard]] attribute in class declaration <https://reviews.llvm.org/D79354> However I feel I made a mistake with the previous fix because the l_square and r_square haven't always been assigned to be of type TT_AttributeSquare yet. Update this patch so the test from both revision still work. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D80008/new/ https://reviews.llvm.org/D80008 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 @@ -8014,6 +8014,30 @@ MultiLineFunctions); } +TEST_F(FormatTest, AttributeClass) { + FormatStyle Style = getChromiumStyle(FormatStyle::LK_Cpp); + verifyFormat("class S {\n" + " S(S&&) = default;\n" + "};", + Style); + verifyFormat("class [[nodiscard]] S {\n" + " S(S&&) = default;\n" + "};", + Style); + verifyFormat("class __attribute((maybeunused)) S {\n" + " S(S&&) = default;\n" + "};", + Style); + verifyFormat("struct S {\n" + " S(S&&) = default;\n" + "};", + Style); + verifyFormat("struct [[nodiscard]] S {\n" + " S(S&&) = default;\n" + "};", + Style); +} + TEST_F(FormatTest, AttributePenaltyBreaking) { FormatStyle Style = getLLVMStyle(); verifyFormat("void ABCDEFGH::ABCDEFGHIJKLMN(\n" Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2404,7 +2404,7 @@ // An [[attribute]] can be before the identifier. while (FormatTok->isOneOf(tok::identifier, tok::coloncolon, tok::hashhash, tok::kw___attribute, tok::kw___declspec, - tok::kw_alignas, TT_AttributeSquare) || + tok::kw_alignas, tok::l_square, tok::r_square) || ((Style.Language == FormatStyle::LK_Java || Style.Language == FormatStyle::LK_JavaScript) && FormatTok->isOneOf(tok::period, tok::comma))) {
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -8014,6 +8014,30 @@ MultiLineFunctions); } +TEST_F(FormatTest, AttributeClass) { + FormatStyle Style = getChromiumStyle(FormatStyle::LK_Cpp); + verifyFormat("class S {\n" + " S(S&&) = default;\n" + "};", + Style); + verifyFormat("class [[nodiscard]] S {\n" + " S(S&&) = default;\n" + "};", + Style); + verifyFormat("class __attribute((maybeunused)) S {\n" + " S(S&&) = default;\n" + "};", + Style); + verifyFormat("struct S {\n" + " S(S&&) = default;\n" + "};", + Style); + verifyFormat("struct [[nodiscard]] S {\n" + " S(S&&) = default;\n" + "};", + Style); +} + TEST_F(FormatTest, AttributePenaltyBreaking) { FormatStyle Style = getLLVMStyle(); verifyFormat("void ABCDEFGH::ABCDEFGHIJKLMN(\n" Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2404,7 +2404,7 @@ // An [[attribute]] can be before the identifier. while (FormatTok->isOneOf(tok::identifier, tok::coloncolon, tok::hashhash, tok::kw___attribute, tok::kw___declspec, - tok::kw_alignas, TT_AttributeSquare) || + tok::kw_alignas, tok::l_square, tok::r_square) || ((Style.Language == FormatStyle::LK_Java || Style.Language == FormatStyle::LK_JavaScript) && FormatTok->isOneOf(tok::period, tok::comma))) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits