Index: clang/lib/Format/WhitespaceManager.cpp =================================================================== --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -17,8 +17,8 @@ namespace clang { namespace format { -bool WhitespaceManager::Change::IsBeforeInFile:: -operator()(const Change &C1, const Change &C2) const { +bool WhitespaceManager::Change::IsBeforeInFile::operator()( + const Change &C1, const Change &C2) const { return SourceMgr.isBeforeInTranslationUnit( C1.OriginalWhitespaceRange.getBegin(), C2.OriginalWhitespaceRange.getBegin()); @@ -465,6 +465,19 @@ // definitions. return C.Tok->is(TT_StartOfName) || C.Tok->is(TT_FunctionDeclarationName) || + C.Tok->startsSequence( + tok::l_paren, tok::l_paren, tok::identifier, tok::coloncolon, + tok::identifier, tok::r_paren, tok::r_paren) || + C.Tok->startsSequence(tok::l_square, tok::l_square, + tok::identifier, tok::coloncolon, + tok::identifier, tok::r_square, + tok::r_square) || + C.Tok->startsSequence(tok::l_square, tok::l_square, + tok::identifier, tok::r_square, + tok::r_square) || + C.Tok->startsSequence(tok::l_paren, tok::l_paren, + tok::identifier, tok::r_paren, + tok::r_paren) || C.Tok->is(tok::kw_operator); }, Changes, /*StartAt=*/0); Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -10135,6 +10135,47 @@ " unsigned c;\n" "}", Alignment); + + // See llvm.org/PR40418 + verifyFormat( + "void f(int extremlylongparameternamexxxxxxxx1,\n" + " long extremlylongparameternamexxxxxxxx2,\n" + " int [[a::b]] extremlylongparameternamexxxxxxxx3,\n" + " int __attribute__((a::b)) extremlylongparameternamexxxxxxxx4) " + "{}\n", + Alignment); + + verifyFormat("void f(int extremlylongparameternamexxxxxxxx1,\n" + " long extremlylongparameternamexxxxxxxx2,\n" + " int [[deprecated]] " + "extremlylongparameternamexxxxxxxx3,\n" + " int __attribute__((deprecated)) " + "extremlylongparameternamexxxxxxxx4) " + "{}\n", + Alignment); + + verifyFormat("int a;\n" + "unsigned long b;\n" + "int __attribute__((a::b)) d;\n" + "int [[a::b]] c;\n" + "int __attribute__((a::b)) e;\n" + "int __attribute__((depreciated)) f;\n" + "int __attribute__((aligned(16))) g;\n", + Alignment); + + verifyFormat("int a;\n" + "unsigned long b;\n" + "int __attribute__((a::b)) d;\n" + "int [[deprecated]] c;\n" + "int __attribute__((a::b)) e;\n", + Alignment); + + verifyFormat("int a;\n" + "unsigned long b;\n" + "int __attribute__((deprecated)) de;\n" + "int [[deprecated]] c;\n" + "int __attribute__((a::b)) e;\n", + Alignment); } TEST_F(FormatTest, LinuxBraceBreaking) {