Skip to content

clang-format using "Macro:" to replace macros does not give expected alignment #140939

Open
@dawdolman

Description

@dawdolman

When using the following .clang-format file on some C++ code that uses Macros to define const arrays of data the formatted output is not as expected:

---
BasedOnStyle: Microsoft
AlignArrayOfStructures: Right
AlignConsecutiveAssignments:
  Enabled: true
AlignConsecutiveBitFields:
  Enabled: true
AlignConsecutiveDeclarations:
  Enabled: true
AlignConsecutiveMacros:
  Enabled: true
AlignConsecutiveShortCaseStatements:
  Enabled: true
AllowShortFunctionsOnASingleLine: Empty
BraceWrapping:
  AfterCaseLabel: false
  AfterClass: true
  AfterControlStatement: Always
  AfterEnum: true
  AfterFunction: true
  AfterNamespace: true
  AfterObjCDeclaration: true
  AfterStruct: true
  AfterUnion: false
  AfterExternBlock: true
  BeforeCatch: true
  BeforeElse: true
  BeforeLambdaBody: false
  BeforeWhile: false
  IndentBraces: false
  SplitEmptyFunction: true
  SplitEmptyRecord: true
  SplitEmptyNamespace: true
NamespaceIndentation: All
PointerAlignment: Left
QualifierAlignment: Left
SpaceBeforeParens: Never
SpacesInAngles: Always
SpacesInParens: Custom
SpacesInParensOptions:
  InConditionalStatements: true
  Other: true
SpacesInSquareBrackets: true
FixNamespaceComments: false

Macros:
  - BeginPropertyTable(a)=const int something[] = { 
  - PropertyEntryString(a,b,c)={ 0 }
  - EndPropertyTable(a)=};

Input and expected results:

const int a[] = {
    { 0 },
    { 0 },
};

BeginPropertyTable( CLocation )
	PropertyEntryString( _P( "description" ), CLocation, m_szDescription ),
	PropertyEntryString( _P( "file" ), CLocation, m_szFile ),
EndPropertyTable( CLocation )

Actual formatting results in the following output where replaced macro elements are grouped into a single line instead of being formatted in the same way as the const int a[] expression above:

const int a[] = {
    { 0 },
    { 0 },
};

BeginPropertyTable( CLocation ) PropertyEntryString( _P( "description" ), CLocation, m_szDescription ),
    PropertyEntryString( _P( "file" ), CLocation, m_szFile ), EndPropertyTable( CLocation )

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions