Skip to content

Commit a84e0b4

Browse files
gedareowenca
authored andcommitted
[clang-format] Fix align consecutive declarations over function pointers
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
1 parent 38a7ef7 commit a84e0b4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ void WhitespaceManager::alignConsecutiveDeclarations() {
870870
AlignTokens(
871871
Style,
872872
[](Change const &C) {
873-
if (C.Tok->is(TT_FunctionDeclarationName))
873+
if (C.Tok->isOneOf(TT_FunctionDeclarationName, TT_FunctionTypeLParen))
874874
return true;
875875
if (C.Tok->isNot(TT_StartOfName))
876876
return false;

clang/unittests/Format/FormatTest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,6 +2059,8 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
20592059
"const unsigned int *d;\n"
20602060
"Const unsigned int &e;\n"
20612061
"const unsigned int &f;\n"
2062+
"int *f1(int *a, int &b, int &&c);\n"
2063+
"double *(*f2)(int *a, double &&b);\n"
20622064
"const unsigned &&g;\n"
20632065
"Const unsigned h;",
20642066
Style);
@@ -2104,6 +2106,8 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
21042106
"const unsigned int* d;\n"
21052107
"Const unsigned int& e;\n"
21062108
"const unsigned int& f;\n"
2109+
"int* f1(int* a, int& b, int&& c);\n"
2110+
"double* (*f2)(int* a, double&& b);\n"
21072111
"const unsigned&& g;\n"
21082112
"Const unsigned h;",
21092113
Style);
@@ -2129,6 +2133,8 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
21292133
"const unsigned int *d;\n"
21302134
"Const unsigned int& e;\n"
21312135
"const unsigned int& f;\n"
2136+
"int *f1(int *a, int& b, int&& c);\n"
2137+
"double *(*f2)(int *a, double&& b);\n"
21322138
"const unsigned g;\n"
21332139
"Const unsigned h;",
21342140
Style);
@@ -2169,6 +2175,8 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
21692175
"const unsigned int* d;\n"
21702176
"Const unsigned int & e;\n"
21712177
"const unsigned int & f;\n"
2178+
"int* f1(int* a, int & b, int && c);\n"
2179+
"double* (*f2)(int* a, double && b);\n"
21722180
"const unsigned && g;\n"
21732181
"Const unsigned h;",
21742182
Style);
@@ -2194,6 +2202,8 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
21942202
"const unsigned int * d;\n"
21952203
"Const unsigned int &e;\n"
21962204
"const unsigned int &f;\n"
2205+
"int * f1(int * a, int &b, int &&c);\n"
2206+
"double * (*f2)(int * a, double &&b);\n"
21972207
"const unsigned &&g;\n"
21982208
"Const unsigned h;",
21992209
Style);

0 commit comments

Comments
 (0)