Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-format Allow for short statement braces in requires clause #59412

Closed
marstaik opened this issue Dec 8, 2022 · 6 comments
Closed

clang-format Allow for short statement braces in requires clause #59412

marstaik opened this issue Dec 8, 2022 · 6 comments
Assignees

Comments

@marstaik
Copy link

marstaik commented Dec 8, 2022

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
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 8, 2022

@llvm/issue-subscribers-clang-format

@Backl1ght
Copy link
Member

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?

@Backl1ght
Copy link
Member

It seems like brace wrapping did not take require into consideration.

I will try implementing it.

@usx95
Copy link
Contributor

usx95 commented Mar 29, 2023

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_;
};

@usx95 usx95 closed this as completed Mar 29, 2023
@rymiel
Copy link
Member

rymiel commented Mar 29, 2023

This is still an issue if using the option BraceWrapping.AfterFunction (that option shouldn't affect requires clauses)

@rymiel rymiel reopened this Mar 29, 2023
@rymiel
Copy link
Member

rymiel commented May 15, 2023

@rymiel rymiel added the awaiting-review Has pending Phabricator review label May 15, 2023
@owenca owenca closed this as completed in 69209e3 Oct 25, 2023
@owenca owenca removed the awaiting-review Has pending Phabricator review label Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

7 participants