<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/60843>60843</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-format] Preprocessor directives lead to exessive indentation and other issues
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Flamefire
      </td>
    </tr>
</table>

<pre>
    Given the following (reduced) `.clangformat` style file:

```
---
Language: Cpp
AllowShortFunctionsOnASingleLine: Inline
BasedOnStyle: 'LLVM'
IndentPPDirectives: AfterHash
IndentWidth: 4
NamespaceIndentation: Inner
CompactNamespaces: True
...
```

I am reformatting the following cpp file:

```
#ifdef TRIGGER_CLANGFORMAT_15+
#    pragma suppress warning
#endif
namespace a { namespace b { namespace c {

 class Foo {
#ifdef TRIGGER_CLANGFORMAT_14
#    pragma suppress warning
#endif
        std::string bar_;

      public:
 const std::string &bar() const { return bar_; }
    };

}}} // namespace a::b::c
```

As you can see no changes are expected. However clang-format-15 up to 17 indent the whole class by an additional 4 spaces.   
clang-format-14 does not do that but it breaks the member function into separate lines although `AllowShortFunctionsOnASingleLine` is set.

A bit more debugging:
- Removing `IndentPPDirectives` or the preprocessor directives fixes the behavior
- The value of `IndentPPDirectives` does not matter, i.e. Before/AfterHash both produce the bug (`None` is the same as removal, i.e. works)
- The bug on clang-format 15+ is triggered by the first preprocessor directive, the one on 14 by the 2nd. No effect of the first on 14 or 2nd on 15+ (i.e. that works) and the names/content seem to be irrelevant.
- The value of `PPIndentWidth` does not matter
- When disabling `CompactNamespaces` the 3 `namespace` declarations are put on separate lines but `namespace c` is already indented despite `NamespaceIndentation: Inner` (happens consistently on version 14-17) so might be a related issue


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVt1u2zwSfRr6ZmBBphzZvvCFk6zTAmkapMH2shiJI4lb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