[clang] a84e0b4 - [clang-format] Fix align consecutive declarations over function pointers
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 6 02:17:42 PDT 2023
Author: Gedare Bloom
Date: 2023-07-06T02:17:32-07:00
New Revision: a84e0b4bdc9999872adbdaafbade8164b197784b
URL: https://github.com/llvm/llvm-project/commit/a84e0b4bdc9999872adbdaafbade8164b197784b
DIFF: https://github.com/llvm/llvm-project/commit/a84e0b4bdc9999872adbdaafbade8164b197784b.diff
LOG: [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
Added:
Modified:
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index 18e9e043bc89f5..03dcc31eb09aef 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -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;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index e0a0a0d004d541..81f2a1361be328 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
More information about the cfe-commits
mailing list