mirror of
https://github.com/intel/llvm.git
synced 2026-01-15 12:25:46 +08:00
[clang-format] Fix a bug in AlignConsecutiveDeclarations (#135516)
Fix #109768
This commit is contained in:
@@ -1012,13 +1012,8 @@ void WhitespaceManager::alignConsecutiveDeclarations() {
|
||||
AlignTokens(
|
||||
Style,
|
||||
[&](Change const &C) {
|
||||
if (Style.AlignConsecutiveDeclarations.AlignFunctionPointers) {
|
||||
for (const auto *Prev = C.Tok->Previous; Prev; Prev = Prev->Previous)
|
||||
if (Prev->is(tok::equal))
|
||||
return false;
|
||||
if (C.Tok->is(TT_FunctionTypeLParen))
|
||||
return true;
|
||||
}
|
||||
if (C.Tok->is(TT_FunctionTypeLParen))
|
||||
return Style.AlignConsecutiveDeclarations.AlignFunctionPointers;
|
||||
if (C.Tok->is(TT_FunctionDeclarationName))
|
||||
return Style.AlignConsecutiveDeclarations.AlignFunctionDeclarations;
|
||||
if (C.Tok->isNot(TT_StartOfName))
|
||||
|
||||
@@ -20207,6 +20207,16 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
|
||||
"double b();",
|
||||
AlignmentLeft);
|
||||
|
||||
auto Style = AlignmentLeft;
|
||||
Style.AlignConsecutiveDeclarations.AlignFunctionPointers = true;
|
||||
Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
|
||||
verifyFormat("int function_name(const wchar_t* title,\n"
|
||||
" int x = 0,\n"
|
||||
" long extraStyle = 0,\n"
|
||||
" bool readOnly = false,\n"
|
||||
" FancyClassType* module = nullptr);",
|
||||
Style);
|
||||
|
||||
// PAS_Middle
|
||||
FormatStyle AlignmentMiddle = Alignment;
|
||||
AlignmentMiddle.PointerAlignment = FormatStyle::PAS_Middle;
|
||||
@@ -20438,7 +20448,7 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
|
||||
Alignment);
|
||||
|
||||
// See PR37175
|
||||
FormatStyle Style = getMozillaStyle();
|
||||
Style = getMozillaStyle();
|
||||
Style.AlignConsecutiveDeclarations.Enabled = true;
|
||||
verifyFormat("DECOR1 /**/ int8_t /**/ DECOR2 /**/\n"
|
||||
"foo(int a);",
|
||||
|
||||
Reference in New Issue
Block a user