llvm / llvm-project

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

clang-format: Allow empty structs and classes on single line #53960

Open AdamBucior opened 2 years ago

AdamBucior commented 2 years ago

When I format this example code:

struct A
{
  int i;
};

struct B {};

class C
{
  void foo();
};

class D {};

With this .clang-format file:

BraceWrapping:
 AfterClass: true
 AfterStruct: true
 SplitEmptyRecord: false

BreakBeforeBraces: Custom

I get this ugly result:

struct A
{
  int i;
};

struct B
{};

class C
{
  void foo();
};

class D
{};

I would like there to be an option to allow empty structs and classes on a single line (so that the example code is left unchanged) just like it is possible with functions by using AllowShortFunctionsOnASingleLine.

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-format

triplejam commented 3 weeks ago

I agree. I want this feature too.

Whenever there is a lot of any sort of template metaprogramming, it's not uncommon for there to be types used simply as some sort of identifier.

Ahajha commented 2 weeks ago

+1 for this. I've seen a few threads asking for this dating back to at least clang 12, would love to have this.