Closed
Description
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 C++ 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 3namespace
declarations are put on separate lines butnamespace c
is already indented despiteNamespaceIndentation: Inner
(happens consistently on version 14-17) so might be a related issue