llvm / llvm/llvm-project

[clang-format] Tabular alignment based on internal operators

Open
#191,320 3 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

`clang-format` does a good job aligning consecutive lines based on assignment operators, but doesn't seem to have any support for other operators after that in a set in given lines. I am trying to make

```cpp
frame |= (static_cast(alisufh) & 0xFULL) << 0U;
frame |= (static_cast(awoeufhldsiuahloiwef) & 0x1ULL) << 4U;
frame |= (static_cast(asdf) & 0x1ULL) << 5U;
frame |= (static_cast(oasiudhoaw9ufheoaweufhw) & 0x1ULL) << 6U;
frame |= (static_cast(auisgfydoayasdfasdf) & 0x1ULL) << 7U;
frame |= (static_cast(hasdfadsfadsf) & 0x1ULL) << 8U;
frame |= (static_cast(asdfas) & 0x1ULL) << 9U;
frame |= (static_cast(biushdfus) & 0x1ULL) << 10U;
```

look like

```cpp
frame |= (static_cast(alisufh) & 0xFULL) << 0U;
frame |= (static_cast(awoeufhldsiuahloiwef) & 0x1ULL) << 4U;
frame |= (static_cast(asdf) & 0x1ULL) << 5U;
frame |= (static_cast(oasiudhoaw9ufheoaweufhw) & 0x1ULL) << 6U;
frame |= (static_cast(auisgfydoayasdfasdf) & 0x1ULL) << 7U;
frame |= (static_cast(hasdfadsfadsf) & 0x1ULL) << 8U;
frame |= (static_cast(asdfas) & 0x1ULL) << 9U;
frame |= (static_cast(biushdfus) & 0x1ULL) << 10U;
```

(the digit-based number alignment at the end is probably a different issue).

Contributor guide

Open the contributing guide

Research direction

Start by running clang-format on the supplied C++ example and compare its output with the requested alignment. Then inspect clang-format's existing operator-alignment handling and formatting tests; done means consecutive lines align the internal operators as shown, without requiring the separate digit-based number alignment.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.