This revision was automatically updated to reflect the committed changes. Closed by commit rG6189dd06ad48: [clang-format] [PR45942] [[nodiscard]] causes && to be miss interpreted as… (authored by MyDeveloperDay).
Repository: rG LLVM Github Monorepo 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