llvm / llvm/llvm-project

[clang-format] Support indentation of preprocessor directives to level of surrounding code

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

Description

Please support indentation of preprocessor directives to level of surrounding code.

I want
```cpp
int main()
{

#warning This is a test!

while (true)
{
DoThingOne();

#ifdef MACRO_A
DoThingThree();
#endif
}

return 0;
}

```
to to be formatted as
```cpp
int main()
{

#warning This is a test!

while (true)
{
DoThingOne();

#ifdef MACRO_A
DoThingThree();
#endif
}

return 0;
}
```

Related: https://www.reddit.com/r/cpp_questions/comments/102vlmu/indent_macros_with_clang_format/

Contributor guide

Open the contributing guide

Research direction

No source file or test is named. Start by locating clang-format's handling of preprocessor directives, then use the issue's C++ examples as the acceptance cases: directives should align with their surrounding code level while nested body statements retain their indentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 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.