clang-format Allow for short statement braces in requires clause
With custom brace styles to always break, there is no way to get one-line requires expressions to exist. In particular I mean the ones that constrain return type via { ... } -> ...;, and I am not sure if they have a formal name.
There probably should be another option for AllowShortRequiresExpressionsOnASingleLine or something similar.
IE:
template<class T>
concept meta_named_type_ = requires( T t ) {
meta_type_<T>;
is_base_of_type<EMetaTag::NamedType>( t.meta_tag );
{
t.name
} -> string_;
{
t.nested_name_specifier
} -> string_;
{
t.metadata
} -> map_;
};
should preferably be:
template<class T>
concept meta_named_type_ = requires( T t ) {
meta_type_<T>;
is_base_of_type<EMetaTag::NamedType>( t.meta_tag );
{ t.name } -> string_;
{ t.nested_name_specifier } -> string_;
{ t.metadata } -> map_;
};
.clang-format 16 config:
StatementMacros: []
Language: Cpp
Standard: c++20
ColumnLimit: 120
IndentWidth: 4
TabWidth: 4
AccessModifierOffset: -4
UseTab: AlignWithSpaces
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
PointerAlignment: Left
AlignAfterOpenBracket: AlwaysBreak
AlignArrayOfStructures: Right
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: None
AlignEscapedNewlines: Left
AlignOperands: AlignAfterOperator
AlignTrailingComments: false
PackConstructorInitializers: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: Never
AllowShortBlocksOnASingleLine: Empty
AllowShortLambdasOnASingleLine: Empty
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
AllowAllArgumentsOnNextLine: false
#AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: Both
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Never
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: false
BeforeElse: true
BeforeLambdaBody: true
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeConceptDeclarations: true
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: false
CompactNamespaces: false
Cpp11BracedListStyle: true
FixNamespaceComments: true
IndentCaseBlocks: false
IndentCaseLabels: true
IndentExternBlock: AfterExternBlock
IndentGotoLabels: false
IndentPPDirectives: None
IndentRequires: false
IndentWrappedFunctionNames: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 3
SpacesInAngles: Never
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: true
SpacesInContainerLiterals: true
SpacesInParentheses: true
SpacesInSquareBrackets: false
MaxEmptyLinesToKeep: 1
SeparateDefinitionBlocks: Always
RequiresClausePosition: OwnLine
IndentRequiresClause: false
RequiresExpressionIndentation: OuterScope
@llvm/issue-subscribers-clang-format
After comment AfterFunction: true I got output below
template<class T>
concept meta_named_type_ = requires( T t ) {
meta_type_<T>;
is_base_of_type<EMetaTag::NamedType>( t.meta_tag );
{ t.name } -> string_;
{ t.nested_name_specifier } -> string_;
{ t.metadata } -> map_;
};
It seems like require expression is recognized as function?
It seems like brace wrapping did not take require into consideration.
I will try implementing it.
This looks to be fixed at trunk
template <class T>
concept meta_named_type_ = requires(T t) {
meta_type_<T>;
is_base_of_type<EMetaTag::NamedType>(t.meta_tag);
{ t.name } -> string_;
{ t.nested_name_specifier } -> string_;
{ t.metadata } -> map_;
};
This is still an issue if using the option BraceWrapping.AfterFunction (that option shouldn't affect requires clauses)
https://reviews.llvm.org/D139834