[clang-format] BasedOnStyle: InheritParentConfig does not inherit AlignAfterOpenBracket
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Summary
When a style uses BasedOnStyle: InheritParentConfig, every option from the parent .clang-format is inherited except AlignAfterOpenBracket, which is silently reset to its default (Align). Other options (e.g. ColumnLimit, IndentWidth, PointerAlignment, NamespaceIndentation, BreakBeforeBraces) inherit correctly. --style=file inherits AlignAfterOpenBracket as expected, so the value in the file is valid and parseable.
Version
clang-format version 22.1.8
(also reproduces on earlier releases)
Steps to reproduce
Create a directory with this .clang-format:
```
AlignAfterOpenBracket: DontAlign
ColumnLimit: 30
```
and t.cpp:
```
void f() {
functionName(alpha, beta, gamma, delta);
}
```
Format the file two ways:
```
$ clang-format --style=file t.cpp
void f() {
functionName(alpha, beta,
gamma, delta);
}
```
```
$ clang-format --style='{BasedOnStyle: InheritParentConfig}' t.cpp
void f() {
functionName(alpha, beta,
gamma, delta);
}
```
The second command inherits the parent config (it picks up ColumnLimit: 30, so the file is being read) but formats with AlignAfterOpenBracket: Align instead of the configured DontAlign.
```
Confirmation via --dump-config
$ clang-format --style=file --assume-filename=t.cpp --dump-config | grep AlignAfterOpenBracket
AlignAfterOpenBracket: false
$ clang-format --style='{BasedOnStyle: InheritParentConfig}' --assume-filename=t.cpp --dump-config | grep AlignAfterOpenBracket
AlignAfterOpenBracket: true
Same file, same directory — only the presence of BasedOnStyle: InheritParentConfig changes the resolved value.
```
Expected
BasedOnStyle: InheritParentConfig should inherit AlignAfterOpenBracket from the parent .clang-format, like every other option, yielding DontAlign here.
Actual
AlignAfterOpenBracket is reset to the default Align; the configured value is dropped.
Note
--dump-config prints AlignAfterOpenBracket as a boolean (true/false) even though it is a four-value enum (Align/DontAlign/AlwaysBreak/BlockIndent). The option retains a legacy boolean mapping, and the inheritance/merge path under BasedOnStyle appears to go through that boolean and lose the enum value. This is likely the same root cause and may point at the fix.
Contributor guide
Research direction
Start in clang-format's configuration inheritance and option-merging path, using the reported .clang-format and t.cpp reproduction. Compare --style=file with --style='{BasedOnStyle: InheritParentConfig}' and inspect --dump-config for AlignAfterOpenBracket; done means the inherited DontAlign value is preserved without regressing the other inherited options.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100