llvm / llvm/llvm-project

[clang-format] Allow excluding preproccesor directives from `IntegerLiteralSeparator`

Open
#161,848 1 comment 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

Given the config

```yaml
IntegerLiteralSeparator:
Decimal: 3
DecimalMinDigits: 5
```

all numbers, *including numbers inside of preprocessor directives*, will have separators inserted:

```cpp
#if __cpp_constexpr >= 201'603L // i.e 2016-03
```

I believe that there is a legitimate use-case for wanting directives to be left as-is, e.g. for feature testing (like above) or if someone wanted to use a C99 preprocessor for their C23/C++14 code.

---

I was thinking the option for it could look something like this:

```yaml
IntegerLiteralSeparator:
Decimal: 3
DecimalMinDigits: 5
PPDirectives: true
```

One could also consider something more fine-grained like `Always`/`Never`/`Leave`, although I can't imagine that being very beneficial.

Contributor guide

Open the contributing guide

Research direction

Start by tracing clang-format's IntegerLiteralSeparator handling for the shown YAML configuration and how integer literals in #if directives are processed. Define and document the intended directive behavior, then add coverage using the configuration and preprocessor example from the issue so the expected unchanged or separated output is explicit.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.