Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[clang-format] There is no option to disable BreakInheritanceList and BreakConstructorInitializers #61156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nebraszka opened this issue Mar 3, 2023 · 2 comments · Fixed by #138440
Assignees

Comments

@nebraszka
Copy link

nebraszka commented Mar 3, 2023

Hi,
I want to achieve this formatting effect:

class D : public A, public B, public C
{
public:
  int id_c;
}; 

typedef enum : int
{
  ALL = 0,
  DEBUG = 1,
  INFO = 2,
  WARN = 3,
  ERROR = 4,
} log_level_t;

I want to use Mozilla style, so I generated .clang-format with Mozilla style parameters:

clang-format -style=mozilla -dump-config > .clang-format

After formatting using this .clang-format file, I got the following:

class D
  : public A
  , public B
  , public C
{
public:
  int id_c;
};

typedef enum
  : int
{
  ALL = 0,
  DEBUG = 1,
  INFO = 2,
  WARN = 3,
  ERROR = 4,
} log_level_t;

Trying to achieve my formatting goal, I found those values in the .clang-format file:

# BasedOnStyle:  Mozilla
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeComma
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma

I want to disable line breaks, but there's no false value for those parameters:

# It doesn't work
BasedOnStyle:  Mozilla
BreakConstructorInitializers: false
BreakConstructorInitializers: false

I was only able to get the effect I wanted by commenting on the relevant parameters:

# BasedOnStyle:  Mozilla
BreakBeforeInheritanceComma: false
#BreakInheritanceList: BeforeComma
BreakConstructorInitializersBeforeComma: false
#BreakConstructorInitializers: BeforeComma

However, with this solution, I have to copy all the parameters from the Mozilla style instead of using BasedOnStyle: Mozilla.
Shouldn't there be an option to disable those parameters connected with breaks?

@llvmbot
Copy link
Member

llvmbot commented Mar 3, 2023

@llvm/issue-subscribers-clang-format

@owenca
Copy link
Contributor

owenca commented May 4, 2025

Hi, I want to achieve this formatting effect:

class D : public A, public B, public C
{
public:
int id_c;
};

typedef enum : int
{
ALL = 0,
DEBUG = 1,
INFO = 2,
WARN = 3,
ERROR = 4,
} log_level_t;

You can do so with #138440 and the .clang-format file below:

BasedOnStyle: Mozilla
BreakInheritanceList: AfterColon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants