Skip to content

clang-format. SeparateDefinitionBlocks inserts spaces after attribute like macro #69591

@yrHeTaTeJlb

Description

@yrHeTaTeJlb

My previous issue was closed with an incorrect resolution.

The problem is that SeparateDefinitionBlocks: Always treats attribute-like macro incorrectly. USTRUCT(), UCLASS(), UPROPERTY() and UENUM() are not definitions, and clang format should not insert an emty line after them.

$ cat .clang-format
SeparateDefinitionBlocks: Always
BreakBeforeBraces: Allman

######################################

$ cat test.cpp
UENUM()
enum class EEnum
{
    Foo,
    Bar,
};
USTRUCT()
struct FStruct
{
    UPROPERTY()
    int baz = 0;
    UFUNCTION()
    int quux(){}
};
UCLASS()
class FClass
{
    void foo(){}
    void bar(){}
};

######################################

$ clang-format.exe --version
clang-format version 17.0.1 (git://code.qt.io/clang/llvm-project.git 1eee682c1df3ce22d1c53c36f9c44cb4bf3df615)

######################################

$ clang-format.exe test.cpp
UENUM()
enum class EEnum
{
  Foo,
  Bar,
};
USTRUCT()

struct FStruct
{
  UPROPERTY()
  int baz = 0;
  UFUNCTION()

  int quux() {}
};
UCLASS()

class FClass
{
  void foo() {}

  void bar() {}
};

######################################

$ cat expected.cpp
UENUM()
enum class EEnum
{
  Foo,
  Bar,
};

USTRUCT()
struct FStruct
{
  UPROPERTY()
  int baz = 0;

  UFUNCTION()
  int quux() {}
};

UCLASS()
class FClass
{
  void foo() {}

  void bar() {}
};

MaxEmptyLinesToKeep has nothing to do there. I neither want my code to get squashed into a single block, nor to align everything manually.

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