Issue 79112
Summary [clang-format] Inconsistent indentation when mixing preprocessor directives and code
Labels clang-format
Assignees
Reporter Grzzlwmpf
    When using `IndentPPDirectives` with anything other than `None`, `clang-format` produces inconsistent output. As an example, the snippet
```c
int foo()
{
  #ifdef foo1
    #ifdef foo2
      #ifdef foo 3
 bar1();
      #endif
      bar2();
    #endif
    bar3();
 #else
    bar4();
  #endif
}
```
is formatted as 
```c
int foo()
{
#ifdef foo1
  #ifdef foo2
    #ifdef foo 3
  bar1(); //line was outdented
    #endif
  bar2(); //line was outdented
  #endif
  bar3();
#else
 bar4();
#endif
}
```
when using `IndentPPDirectives: BeforeHash` (the output of `AfterHash` is analogous).

It seems that the indentation of PP directives is computed completely independently from other code, which somewhat defeats the purpose of indenting them in the first place.
I'd expect using PP indentation would either "sync" the indent levels of PP directives and code (so control statemenmts in PP directives would indent the follwing code block and vice versa) or at least not "unformat" manual indentation.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to