diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -866,7 +866,7 @@ AlignTokens( Style, [](Change const &C) { - if (C.Tok->is(TT_FunctionDeclarationName)) + if (C.Tok->isOneOf(TT_FunctionDeclarationName, TT_FunctionTypeLParen)) return true; if (C.Tok->isNot(TT_StartOfName)) return false; 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 @@ -2059,6 +2059,8 @@ "const unsigned int *d;\n" "Const unsigned int &e;\n" "const unsigned int &f;\n" + "int *f1(int *a, int &b, int &&c);\n" + "double *(*f2)(int *a, double &&b);\n" "const unsigned &&g;\n" "Const unsigned h;", Style); @@ -2104,6 +2106,8 @@ "const unsigned int* d;\n" "Const unsigned int& e;\n" "const unsigned int& f;\n" + "int* f1(int* a, int& b, int&& c);\n" + "double* (*f2)(int* a, double&& b);\n" "const unsigned&& g;\n" "Const unsigned h;", Style); @@ -2129,6 +2133,8 @@ "const unsigned int *d;\n" "Const unsigned int& e;\n" "const unsigned int& f;\n" + "int *f1(int *a, int& b, int&& c);\n" + "double *(*f2)(int *a, double&& b);\n" "const unsigned g;\n" "Const unsigned h;", Style); @@ -2169,6 +2175,8 @@ "const unsigned int* d;\n" "Const unsigned int & e;\n" "const unsigned int & f;\n" + "int* f1(int* a, int & b, int && c);\n" + "double* (*f2)(int* a, double && b);\n" "const unsigned && g;\n" "Const unsigned h;", Style); @@ -2189,6 +2197,17 @@ verifyFormat("for (int a = 0, b = 0; const Foo * c : {1, 2, 3})", Style); verifyFormat("for (int a = 0, b++; const Foo * c : {1, 2, 3})", Style); + Style.AlignConsecutiveDeclarations.Enabled = true; + verifyFormat("Const unsigned int * c;\n" + "const unsigned int * d;\n" + "Const unsigned int &e;\n" + "const unsigned int &f;\n" + "int * f1(int * a, int &b, int &&c);\n" + "double * (*f2)(int * a, double &&b);\n" + "const unsigned &&g;\n" + "Const unsigned h;", + Style); + // FIXME: we don't handle this yet, so output may be arbitrary until it's // specifically handled // verifyFormat("int Add2(BTree * &Root, char * szToAdd)", Style);