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 @@ -14,6 +14,7 @@ #include "UnwrappedLineParser.h" #include "FormatToken.h" +#include "clang/Basic/TokenKinds.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" @@ -1007,7 +1008,7 @@ if (!Tok->isOneOf(tok::kw_int, tok::kw_char, tok::kw_float, tok::kw_double, tok::kw_struct, tok::kw_union, tok::kw_long, tok::kw_short, - tok::kw_unsigned, tok::kw_register, tok::identifier)) + tok::kw_unsigned, tok::kw_register)) return false; Tok = Tok->Previous; @@ -1378,7 +1379,8 @@ break; if (Previous->Previous && Previous->Previous->is(tok::at)) break; - if (isC78ParameterDecl(FormatTok)) { + if (!Line->Tokens.begin()->Tok->is(tok::kw_typedef) && + isC78ParameterDecl(FormatTok)) { addUnwrappedLine(); return; } 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 @@ -8247,14 +8247,25 @@ " return a + b < c;\n" "};", Style); - // The return breaking style doesn't affect object definitions with - // attribute-like macros. + + // The return breaking style doesn't affect: + // * function and object definitions with attribute-like macros verifyFormat("Tttttttttttttttttttttttt ppppppppppppppp\n" " ABSL_GUARDED_BY(mutex) = {};", getGoogleStyleWithColumns(40)); verifyFormat("Tttttttttttttttttttttttt ppppppppppppppp\n" " ABSL_GUARDED_BY(mutex); // comment", getGoogleStyleWithColumns(40)); + verifyFormat("Tttttttttttttttttttttttt ppppppppppppppp\n" + " ABSL_GUARDED_BY(mutex1)\n" + " ABSL_GUARDED_BY(mutex2);", + getGoogleStyleWithColumns(40)); + verifyFormat("Tttttt f(int a, int b)\n" + " ABSL_GUARDED_BY(mutex1)\n" + " ABSL_GUARDED_BY(mutex2);", + getGoogleStyleWithColumns(40)); + // * typedefs + verifyFormat("typedef ATTR(X) char x;", getGoogleStyle()); Style = getGNUStyle();