Skip to content

Commit

Permalink
[clang-format] Fix align consecutive declarations over function pointers
Browse files Browse the repository at this point in the history
Fixes a bug that prevents alignment from proceeding through a function
pointer in a list of declarations.

Fixes #63451.

Differential Revision: https://reviews.llvm.org/D153585
  • Loading branch information
gedare authored and owenca committed Jul 6, 2023
1 parent 38a7ef7 commit a84e0b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Format/WhitespaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ void WhitespaceManager::alignConsecutiveDeclarations() {
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;
Expand Down
10 changes: 10 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,8 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
"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);
Expand Down Expand Up @@ -2104,6 +2106,8 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
"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);
Expand All @@ -2129,6 +2133,8 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
"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);
Expand Down Expand Up @@ -2169,6 +2175,8 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
"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);
Expand All @@ -2194,6 +2202,8 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
"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);
Expand Down

0 comments on commit a84e0b4

Please sign in to comment.