llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.4k stars 11.74k forks source link

AlignConsecutiveDeclarations and PointerAlignment should support double pointers spaces #57605

Open 3v1n0 opened 2 years ago

3v1n0 commented 2 years ago

Original Issue: https://bugs.llvm.org/show_bug.cgi?id=51861 (https://github.com/llvm/llvm-project/issues/51203)

When using a config including:

PointerAlignment: Right
AlignConsecutiveDeclarations: true

with code such as:

static void
foo_function (int *ptr,
              const char *path,
              GError **error)

We get:

static void
foo_function (int        *ptr,
              const char *path,
              GError    **error)

While an extra space can be expected:


static void
foo_function (int         *ptr,
              const char  *path,
              GError     **error)

Not sure if this should be available through another AlignConsecutivePointerDeclarationStyle option.

/cc @jadahl

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-format

mydeveloperday commented 2 years ago

Can you please provide a complete .clang-format file that generates this issue, by default your repo case comes out as

static void foo_function(int ptr, const char path, GError **error)

3v1n0 commented 2 years ago

Here it's what I'm using:

---
Language: Cpp
AlignAfterOpenBracket: Align
AlignArrayOfStructures: Left
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
# AlignConsecutiveDeclarations is not yet fully correct:
# - https://bugs.llvm.org/show_bug.cgi?id=51860
# - https://bugs.llvm.org/show_bug.cgi?id=51861
AlignConsecutiveDeclarations: Consecutive
AlignConsecutiveMacros: None
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: All
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: GNU
BreakBeforeTernaryOperators: true
BreakBeforeBinaryOperators: None
BitFieldColonSpacing: Both
# ColumnLimit: '80'
# Our column limit is actually 80, but setting that results in clang-format
# making a lot of dubious hanging-indent choices; disable it and assume the
# developer will line wrap appropriately. clang-format will still check
# existing hanging indents.
# ColumnLimit: 0
ContinuationIndentWidth: 2
EmptyLineBeforeAccessModifier: LogicalBlock
IncludeBlocks: Regroup
IncludeCategories:
  - Regex:           '^"config.h"'
    Priority:        -1
  - Regex:           '<[[:alnum:].]+>'
    Priority:        2
  - Regex:           '"[[:alnum:].]+/'
    Priority:        3
  - Regex:           '.*'
    Priority:        4
IndentWidth: 2
IndentWrappedFunctionNames: false
IndentPPDirectives: AfterHash
IndentCaseBlocks: true
IndentExternBlockStyle: NoIndent
InsertTrailingCommas: true
KeepEmptyLinesAtTheStartOfBlocks: false
PointerAlignment: Right
ReferenceAlignment: Right
# SpaceAroundPointerQualifiers: Default
PenaltyBreakBeforeFirstCallParameter: 100
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Always
SpaceBeforeCaseColon: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpacesInParentheses: false
SpacesInSquareBrackets: false
StatementMacros:
  - G_DEFINE_ABSTRACT_TYPE
  - G_DEFINE_ABSTRACT_TYPE_WITH_CODE
  - G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE
  - G_DEFINE_AUTOPTR_CLEANUP_FUNC
  - G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC
  - G_DEFINE_AUTO_CLEANUP_FREE_FUNC
  - G_DEFINE_BOXED_TYPE
  - G_DEFINE_BOXED_TYPE_WITH_CODE
  - G_DEFINE_FINAL_TYPE
  - G_DEFINE_FINAL_TYPE_WITH_CODE
  - G_DEFINE_FINAL_TYPE_WITH_PRIVATE
  - G_DEFINE_INTERFACE
  - G_DEFINE_INTERFACE_WITH_CODE
  - G_DEFINE_POINTER_TYPE
  - G_DEFINE_POINTER_TYPE_WITH_CODE
  - G_DEFINE_QUARK
  - G_DEFINE_TYPE
  - G_DEFINE_TYPE_EXTENDED
  - G_DEFINE_TYPE_WITH_CODE
  - G_DEFINE_TYPE_WITH_PRIVATE
TypenameMacros:
  - G_OBJECT
UseTab: Never