Reputation: 718
I am using clang-format-14 to format my C++ code. I wrote a concept for a buffer class which acts similar to iostream objects, and I want it to look like this:
template <typename T>
concept Data = requires(T & t, Buffer & buffer) {
{ buffer << t } -> std::same_as<Buffer &>;
{ buffer >> t } -> std::same_as<Buffer &>;
};
But when I use clang-format-14 to format the file, I get this instead:
template <typename T>
concept Data = requires(T & t, Buffer & buffer) {
{ buffer << t } -> std::same_as<Buffer &>;
{ buffer >> t } -> std::same_as<Buffer &>;
};
I have no idea where the spaces are coming from.
The first two lines inside the braces preserved the leading tabulators (it's impossible to see on StackOverflow, even with highlighting the whitespace). The three lines were indented with what looks like 15 spaces each.
This is my .clang-format
file:
# Pointers and references
PointerAlignment: Middle
# Indentation
UseTab: ForIndentation
IndentWidth: 2
TabWidth: 2
AccessModifierOffset: -2
# That weird function inlining
AllowShortFunctionsOnASingleLine: None
# Breaking
BreakBeforeBraces: Attach
AlignAfterOpenBracket: BlockIndent
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
# Namespaces
NamespaceIndentation: All
FixNamespaceComments: true
The IndentRequires
option does not influence this behaviour (and obviously neither does BreakBeforeConceptDeclarations
). Although it's interesting that BreakBeforeConceptDeclarations
doesn't have any effect whatsoever and results in a broken concept declaration either way.
The style options I know of are listed on this page.
Upvotes: 4
Views: 897
Reputation: 145
I have no idea where the spaces are coming from
The body of the requires-expression is being aligned to the keyword requires
; however there isn't currently a way to disable that alignment.
This is a bug/deficiency in clang-format, as outlined in https://github.com/llvm/llvm-project/issues/56283.
The fix for this, however, is close to being merged to LLVM main. Even then, the earliest version this fix would apply to would be clang-format 16
Upvotes: 2