diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/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))) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/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"