llvm / llvm/llvm-project

clang-format silently fail on some ConstructorInitializer

Open
#204,698 2 comments 0 reactions 0 assignees View on GitHub
clang-format
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```yaml
IndentWidth: 4
ContinuationIndentWidth: 4
ColumnLimit: 80
BreakBeforeBraces: Allman
AlignOperands: DontAlign

AlignAfterOpenBracket: false

BreakBeforeBinaryOperators: NonAssignment
PenaltyBreakAssignment: 150

BreakBeforeTernaryOperators: true

BreakConstructorInitializers: BeforeComma
ConstructorInitializerIndentWidth: 4
PackConstructorInitializers: Never

BinPackParameters: false
AllowAllParametersOfDeclarationOnNextLine: true
BreakAfterOpenBracketFunction: true
BreakBeforeCloseBracketFunction: true
BreakAfterOpenBracketBracedList: true
BreakBeforeCloseBracketBracedList: true
```

clang-format-22 to format:
```cpp
class some_random_class_a_t
{
public:
some_random_class_a_t(settings_t s) : settings{std::move(s)},
manifest{load_json_nl(settings.manifest_path).get()},
view_definition{pick_view()},
transform{load_perspective(view_definition)},
hdf5_reader{settings.mask_path, settings.io_fmt, settings.input_hw},window{settings.offscreen ? nullptr : new window_glfw_t{Size2D{settings.overview_info.width, settings.overview_info.height}, "tracklab_graph_tracker"}}
{}
};

class some_random_class_b_t
{
public:
some_random_class_b_t(settings_t s) : settings{std::move(s)},
manifest{load_json_nl(settings.manifest_path).get()},
view_definition{pick_view()},
transform{load_perspective(view_definition)},
offscreen_ctx{settings.offscreen ? make_offscreen_context(0): std::unique_ptr{}}
{}
};
class some_random_class_c_t
{
public:
some_random_class_c_t(settings_t s) : settings{std::move(s)},
manifest{load_json_nl(settings.manifest_path).get()},
view_definition{pick_view()},
transform{load_perspective(view_definition)},
hdf5_reader{settings.mask_path, settings.io_fmt, settings.input_hw},window{settings.offscreen ? nullptr : new window_glfw_t{Size2D{settings.overview_info.width, settings.overview_info.height}, "tracklab_graph_tracker"}},
offscreen_ctx{settings.offscreen ? make_offscreen_context(0): std::unique_ptr{}}
{}
};

```

results in:
```cpp
class some_random_class_a_t
{
public:
some_random_class_a_t(settings_t s)
: settings{std::move(s)}
, manifest{load_json_nl(settings.manifest_path)
.get()}
, view_definition{pick_view()}
, transform{load_perspective(view_definition)}
, hdf5_reader{settings.mask_path, settings.io_fmt, settings.input_hw}
, window{
settings.offscreen ? nullptr
: new window_glfw_t{
Size2D{
settings.overview_info.width,
settings.overview_info.height
},
"tracklab_graph_tracker"
}
}
{
}
};

class some_random_class_b_t
{
public:
some_random_class_b_t(settings_t s)
: settings{std::move(s)}
, manifest{load_json_nl(settings.manifest_path)
.get()}
, view_definition{pick_view()}
, transform{load_perspective(view_definition)}
, offscreen_ctx{
settings.offscreen
? make_offscreen_context(0)
: std::unique_ptr{}
}
{
}
};
class some_random_class_c_t
{
public:
some_random_class_c_t(settings_t s) : settings{std::move(s)},
manifest{load_json_nl(settings.manifest_path).get()},
view_definition{pick_view()},
transform{load_perspective(view_definition)},
hdf5_reader{settings.mask_path, settings.io_fmt, settings.input_hw},window{settings.offscreen ? nullptr : new window_glfw_t{Size2D{settings.overview_info.width, settings.overview_info.height}, "tracklab_graph_tracker"}},
offscreen_ctx{settings.offscreen ? make_offscreen_context(0): std::unique_ptr{}}
{
}
};

```

it fail to break lines in some_random_class_c_t

Contributor guide

Open the contributing guide

Research direction

Run clang-format-22 with the supplied YAML configuration against the three constructor examples and compare the output for classes A, B, and C. Trace the constructor-initializer formatting path to determine why class C is left unchanged, then verify that the same input is formatted consistently without changing the intended initializer layout.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.