diff options
author | Brad House <brad@brad-house.com> | 2024-10-06 20:46:43 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-06 17:46:43 -0700 |
commit | f0bd62d8709a49dd87eb75411e41e2e11e0ab59d (patch) | |
tree | d4dd33a3ca91a69d146ddab9497b4e1d328a52ae /clang/lib/Format | |
parent | c4d89203f3822b0466f5cc58654cb016aeb86648 (diff) | |
download | llvm-f0bd62d8709a49dd87eb75411e41e2e11e0ab59d.zip llvm-f0bd62d8709a49dd87eb75411e41e2e11e0ab59d.tar.gz llvm-f0bd62d8709a49dd87eb75411e41e2e11e0ab59d.tar.bz2 |
[clang-format] Add AlignFunctionDeclarations to AlignConsecutiveDeclarations (#108241)
Enabling AlignConsecutiveDeclarations also aligns function prototypes
or declarations. This is often unexpected as typically function
prototypes, especially in public headers, don't use any padding.
Setting AlignFunctionDeclarations to false will skip this alignment.
It is by default set to true to keep compatibility with prior
versions to not make unexpected changes.
Fixes #74320
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/Format.cpp | 35 | ||||
-rw-r--r-- | clang/lib/Format/WhitespaceManager.cpp | 2 |
2 files changed, 21 insertions, 16 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 5350c66..01b4b6f 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -44,43 +44,45 @@ struct ScalarEnumerationTraits<FormatStyle::BreakBeforeNoexceptSpecifierStyle> { template <> struct MappingTraits<FormatStyle::AlignConsecutiveStyle> { static void enumInput(IO &IO, FormatStyle::AlignConsecutiveStyle &Value) { - IO.enumCase(Value, "None", - FormatStyle::AlignConsecutiveStyle( - {/*Enabled=*/false, /*AcrossEmptyLines=*/false, - /*AcrossComments=*/false, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + IO.enumCase(Value, "None", FormatStyle::AlignConsecutiveStyle({})); IO.enumCase(Value, "Consecutive", FormatStyle::AlignConsecutiveStyle( {/*Enabled=*/true, /*AcrossEmptyLines=*/false, /*AcrossComments=*/false, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + /*AlignFunctionDeclarations=*/true, + /*AlignFunctionPointers=*/false, + /*PadOperators=*/true})); IO.enumCase(Value, "AcrossEmptyLines", FormatStyle::AlignConsecutiveStyle( {/*Enabled=*/true, /*AcrossEmptyLines=*/true, /*AcrossComments=*/false, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + /*AlignFunctionDeclarations=*/true, + /*AlignFunctionPointers=*/false, + /*PadOperators=*/true})); IO.enumCase(Value, "AcrossComments", FormatStyle::AlignConsecutiveStyle( {/*Enabled=*/true, /*AcrossEmptyLines=*/false, /*AcrossComments=*/true, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + /*AlignFunctionDeclarations=*/true, + /*AlignFunctionPointers=*/false, + /*PadOperators=*/true})); IO.enumCase(Value, "AcrossEmptyLinesAndComments", FormatStyle::AlignConsecutiveStyle( {/*Enabled=*/true, /*AcrossEmptyLines=*/true, /*AcrossComments=*/true, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + /*AlignFunctionDeclarations=*/true, + /*AlignFunctionPointers=*/false, + /*PadOperators=*/true})); // For backward compatibility. IO.enumCase(Value, "true", FormatStyle::AlignConsecutiveStyle( {/*Enabled=*/true, /*AcrossEmptyLines=*/false, /*AcrossComments=*/false, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); - IO.enumCase(Value, "false", - FormatStyle::AlignConsecutiveStyle( - {/*Enabled=*/false, /*AcrossEmptyLines=*/false, - /*AcrossComments=*/false, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + /*AlignFunctionDeclarations=*/true, + /*AlignFunctionPointers=*/false, + /*PadOperators=*/true})); + IO.enumCase(Value, "false", FormatStyle::AlignConsecutiveStyle({})); } static void mapping(IO &IO, FormatStyle::AlignConsecutiveStyle &Value) { @@ -88,6 +90,8 @@ template <> struct MappingTraits<FormatStyle::AlignConsecutiveStyle> { IO.mapOptional("AcrossEmptyLines", Value.AcrossEmptyLines); IO.mapOptional("AcrossComments", Value.AcrossComments); IO.mapOptional("AlignCompound", Value.AlignCompound); + IO.mapOptional("AlignFunctionDeclarations", + Value.AlignFunctionDeclarations); IO.mapOptional("AlignFunctionPointers", Value.AlignFunctionPointers); IO.mapOptional("PadOperators", Value.PadOperators); } @@ -1449,6 +1453,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { LLVMStyle.AlignConsecutiveAssignments.PadOperators = true; LLVMStyle.AlignConsecutiveBitFields = {}; LLVMStyle.AlignConsecutiveDeclarations = {}; + LLVMStyle.AlignConsecutiveDeclarations.AlignFunctionDeclarations = true; LLVMStyle.AlignConsecutiveMacros = {}; LLVMStyle.AlignConsecutiveShortCaseStatements = {}; LLVMStyle.AlignConsecutiveTableGenBreakingDAGArgColons = {}; diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index fd4a40a..b6b2467 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -1020,7 +1020,7 @@ void WhitespaceManager::alignConsecutiveDeclarations() { return true; } if (C.Tok->is(TT_FunctionDeclarationName)) - return true; + return Style.AlignConsecutiveDeclarations.AlignFunctionDeclarations; if (C.Tok->isNot(TT_StartOfName)) return false; if (C.Tok->Previous && |