clang 17.0.0git
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
clang::format::FormatStyle Struct Reference

The FormatStyle is used to configure the formatting to follow specific guidelines. More...

#include "clang/Format/Format.h"

Classes

struct  AlignConsecutiveStyle
 Alignment options. More...
 
struct  BraceWrappingFlags
 Precise control over the wrapping of braces. More...
 
struct  FormatStyleSet
 
struct  IntegerLiteralSeparatorStyle
 Separator format of integer literals of different bases. More...
 
struct  RawStringFormat
 See documentation of RawStringFormats. More...
 
struct  SpaceBeforeParensCustom
 Precise control over the spacing before parentheses. More...
 
struct  SpacesInLineComment
 Control of spaces within a single line comment. More...
 
struct  TrailingCommentsAlignmentStyle
 Alignment options. More...
 

Public Types

enum  BracketAlignmentStyle : int8_t { BAS_Align , BAS_DontAlign , BAS_AlwaysBreak , BAS_BlockIndent }
 Different styles for aligning after open brackets. More...
 
enum  ArrayInitializerAlignmentStyle : int8_t { AIAS_Left , AIAS_Right , AIAS_None }
 Different style for aligning array initializers. More...
 
enum  EscapedNewlineAlignmentStyle : int8_t { ENAS_DontAlign , ENAS_Left , ENAS_Right }
 Different styles for aligning escaped newlines. More...
 
enum  OperandAlignmentStyle : int8_t { OAS_DontAlign , OAS_Align , OAS_AlignAfterOperator }
 Different styles for aligning operands. More...
 
enum  TrailingCommentsAlignmentKinds : int8_t { TCAS_Leave , TCAS_Always , TCAS_Never }
 Enums for AlignTrailingComments. More...
 
enum  ShortBlockStyle : int8_t { SBS_Never , SBS_Empty , SBS_Always }
 Different styles for merging short blocks containing at most one statement. More...
 
enum  ShortFunctionStyle : int8_t {
  SFS_None , SFS_InlineOnly , SFS_Empty , SFS_Inline ,
  SFS_All
}
 Different styles for merging short functions containing at most one statement. More...
 
enum  ShortIfStyle : int8_t { SIS_Never , SIS_WithoutElse , SIS_OnlyFirstIf , SIS_AllIfsAndElse }
 Different styles for handling short if statements. More...
 
enum  ShortLambdaStyle : int8_t { SLS_None , SLS_Empty , SLS_Inline , SLS_All }
 Different styles for merging short lambdas containing at most one statement. More...
 
enum  DefinitionReturnTypeBreakingStyle : int8_t { DRTBS_None , DRTBS_All , DRTBS_TopLevel }
 Different ways to break after the function definition return type. More...
 
enum  ReturnTypeBreakingStyle : int8_t {
  RTBS_None , RTBS_All , RTBS_TopLevel , RTBS_AllDefinitions ,
  RTBS_TopLevelDefinitions
}
 Different ways to break after the function definition or declaration return type. More...
 
enum  BreakTemplateDeclarationsStyle : int8_t { BTDS_No , BTDS_MultiLine , BTDS_Yes }
 Different ways to break after the template declaration. More...
 
enum  BitFieldColonSpacingStyle : int8_t { BFCS_Both , BFCS_None , BFCS_Before , BFCS_After }
 Styles for adding spacing around : in bitfield definitions. More...
 
enum  BraceWrappingAfterControlStatementStyle : int8_t { BWACS_Never , BWACS_MultiLine , BWACS_Always }
 Different ways to wrap braces after control statements. More...
 
enum  AttributeBreakingStyle : int8_t { ABS_Always , ABS_Leave , ABS_Never }
 Different ways to break after attributes. More...
 
enum  BinPackStyle : int8_t { BPS_Auto , BPS_Always , BPS_Never }
 The style of wrapping parameters on the same line (bin-packed) or on one line each. More...
 
enum  BinaryOperatorStyle : int8_t { BOS_None , BOS_NonAssignment , BOS_All }
 The style of breaking before or after binary operators. More...
 
enum  BraceBreakingStyle : int8_t {
  BS_Attach , BS_Linux , BS_Mozilla , BS_Stroustrup ,
  BS_Allman , BS_Whitesmiths , BS_GNU , BS_WebKit ,
  BS_Custom
}
 Different ways to attach braces to their surrounding context. More...
 
enum  BreakBeforeConceptDeclarationsStyle : int8_t { BBCDS_Never , BBCDS_Allowed , BBCDS_Always }
 Different ways to break before concept declarations. More...
 
enum  BreakBeforeInlineASMColonStyle : int8_t { BBIAS_Never , BBIAS_OnlyMultiline , BBIAS_Always }
 Different ways to break ASM parameters. More...
 
enum  BreakConstructorInitializersStyle : int8_t { BCIS_BeforeColon , BCIS_BeforeComma , BCIS_AfterColon }
 Different ways to break initializers. More...
 
enum  BreakInheritanceListStyle : int8_t { BILS_BeforeColon , BILS_BeforeComma , BILS_AfterColon , BILS_AfterComma }
 Different ways to break inheritance list. More...
 
enum  EmptyLineAfterAccessModifierStyle : int8_t { ELAAMS_Never , ELAAMS_Leave , ELAAMS_Always }
 Different styles for empty line after access modifiers. More...
 
enum  EmptyLineBeforeAccessModifierStyle : int8_t { ELBAMS_Never , ELBAMS_Leave , ELBAMS_LogicalBlock , ELBAMS_Always }
 Different styles for empty line before access modifiers. More...
 
enum  IndentExternBlockStyle : int8_t { IEBS_AfterExternBlock , IEBS_NoIndent , IEBS_Indent }
 Indents extern blocks. More...
 
enum  PPDirectiveIndentStyle : int8_t { PPDIS_None , PPDIS_AfterHash , PPDIS_BeforeHash }
 Options for indenting preprocessor directives. More...
 
enum  TrailingCommaStyle : int8_t { TCS_None , TCS_Wrapped }
 The style of inserting trailing commas into container literals. More...
 
enum  JavaScriptQuoteStyle : int8_t { JSQS_Leave , JSQS_Single , JSQS_Double }
 Quotation styles for JavaScript strings. More...
 
enum  LambdaBodyIndentationKind : int8_t { LBI_Signature , LBI_OuterScope }
 Indentation logic for lambda bodies. More...
 
enum  LanguageKind : int8_t {
  LK_None , LK_Cpp , LK_CSharp , LK_Java ,
  LK_JavaScript , LK_Json , LK_ObjC , LK_Proto ,
  LK_TableGen , LK_TextProto , LK_Verilog
}
 Supported languages. More...
 
enum  LineEndingStyle : int8_t { LE_LF , LE_CRLF , LE_DeriveLF , LE_DeriveCRLF }
 Line ending style. More...
 
enum  NamespaceIndentationKind : int8_t { NI_None , NI_Inner , NI_All }
 Different ways to indent namespace contents. More...
 
enum  PackConstructorInitializersStyle : int8_t {
  PCIS_Never , PCIS_BinPack , PCIS_CurrentLine , PCIS_NextLine ,
  PCIS_NextLineOnly
}
 Different ways to try to fit all constructor initializers on a line. More...
 
enum  PointerAlignmentStyle : int8_t { PAS_Left , PAS_Right , PAS_Middle }
 The &, && and * alignment style. More...
 
enum  QualifierAlignmentStyle : int8_t { QAS_Leave , QAS_Left , QAS_Right , QAS_Custom }
 Different specifiers and qualifiers alignment styles. More...
 
enum  ReferenceAlignmentStyle : int8_t { RAS_Pointer , RAS_Left , RAS_Right , RAS_Middle }
 The & and && alignment style. More...
 
enum  RequiresClausePositionStyle : int8_t { RCPS_OwnLine , RCPS_WithPreceding , RCPS_WithFollowing , RCPS_SingleLine }
 The possible positions for the requires clause. More...
 
enum  RequiresExpressionIndentationKind : int8_t { REI_OuterScope , REI_Keyword }
 Indentation logic for requires expression bodies. More...
 
enum  SeparateDefinitionStyle : int8_t { SDS_Leave , SDS_Always , SDS_Never }
 The style if definition blocks should be separated. More...
 
enum  SortIncludesOptions : int8_t { SI_Never , SI_CaseSensitive , SI_CaseInsensitive }
 Include sorting options. More...
 
enum  SortJavaStaticImportOptions : int8_t { SJSIO_Before , SJSIO_After }
 Position for Java Static imports. More...
 
enum  SortUsingDeclarationsOptions : int8_t { SUD_Never , SUD_Lexicographic , SUD_LexicographicNumeric }
 Using declaration sorting options. More...
 
enum  SpaceAroundPointerQualifiersStyle : int8_t { SAPQ_Default , SAPQ_Before , SAPQ_After , SAPQ_Both }
 Different ways to put a space before opening parentheses. More...
 
enum  SpaceBeforeParensStyle : int8_t {
  SBPO_Never , SBPO_ControlStatements , SBPO_ControlStatementsExceptControlMacros , SBPO_NonEmptyParentheses ,
  SBPO_Always , SBPO_Custom
}
 Different ways to put a space before opening parentheses. More...
 
enum  SpacesInAnglesStyle : int8_t { SIAS_Never , SIAS_Always , SIAS_Leave }
 Styles for adding spacing after < and before `> in template argument lists. More...
 
enum  LanguageStandard : int8_t {
  LS_Cpp03 , LS_Cpp11 , LS_Cpp14 , LS_Cpp17 ,
  LS_Cpp20 , LS_Latest , LS_Auto
}
 Supported language standards for parsing and formatting C++ constructs. More...
 
enum  UseTabStyle : int8_t {
  UT_Never , UT_ForIndentation , UT_ForContinuationAndIndentation , UT_AlignWithSpaces ,
  UT_Always
}
 This option is deprecated. More...
 

Public Member Functions

bool isCpp () const
 
bool isCSharp () const
 
bool isJson () const
 
bool isJavaScript () const
 
bool isVerilog () const
 
bool isProto () const
 
bool operator== (const FormatStyle &R) const
 
std::optional< FormatStyleGetLanguageStyle (LanguageKind Language) const
 

Static Public Member Functions

static FormatStyleSet BuildStyleSetFromConfiguration (const FormatStyle &MainStyle, const std::vector< FormatStyle > &ConfigurationStyles)
 

Public Attributes

bool InheritsParentConfig
 
int AccessModifierOffset
 The extra indent or outdent of access modifiers, e.g.
 
BracketAlignmentStyle AlignAfterOpenBracket
 If true, horizontally aligns arguments after an open bracket.
 
ArrayInitializerAlignmentStyle AlignArrayOfStructures
 if not None, when using initialization for an array of structs aligns the fields into columns.
 
AlignConsecutiveStyle AlignConsecutiveMacros
 Style of aligning consecutive macro definitions.
 
AlignConsecutiveStyle AlignConsecutiveAssignments
 Style of aligning consecutive assignments.
 
AlignConsecutiveStyle AlignConsecutiveBitFields
 Style of aligning consecutive bit fields.
 
AlignConsecutiveStyle AlignConsecutiveDeclarations
 Style of aligning consecutive declarations.
 
EscapedNewlineAlignmentStyle AlignEscapedNewlines
 Options for aligning backslashes in escaped newlines.
 
OperandAlignmentStyle AlignOperands
 If true, horizontally align operands of binary and ternary expressions.
 
TrailingCommentsAlignmentStyle AlignTrailingComments
 Control of trailing comments.
 
bool AllowAllArgumentsOnNextLine
 If a function call or braced initializer list doesn't fit on a line, allow putting all arguments onto the next line, even if BinPackArguments is false.
 
bool AllowAllParametersOfDeclarationOnNextLine
 This option is deprecated.
 
ShortBlockStyle AllowShortBlocksOnASingleLine
 Dependent on the value, while (true) { continue; } can be put on a single line.
 
bool AllowShortCaseLabelsOnASingleLine
 If true, short case labels will be contracted to a single line.
 
bool AllowShortEnumsOnASingleLine
 Allow short enums on a single line.
 
ShortFunctionStyle AllowShortFunctionsOnASingleLine
 Dependent on the value, int f() { return 0; } can be put on a single line.
 
ShortIfStyle AllowShortIfStatementsOnASingleLine
 Dependent on the value, if (a) return; can be put on a single line.
 
ShortLambdaStyle AllowShortLambdasOnASingleLine
 Dependent on the value, auto lambda []() { return 0; } can be put on a single line.
 
bool AllowShortLoopsOnASingleLine
 If true, while (true) continue; can be put on a single line.
 
DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType
 The function definition return type breaking style to use.
 
ReturnTypeBreakingStyle AlwaysBreakAfterReturnType
 The function declaration return type breaking style to use.
 
bool AlwaysBreakBeforeMultilineStrings
 If true, always break before multiline string literals.
 
BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations
 The template declaration breaking style to use.
 
std::vector< std::string > AttributeMacros
 A vector of strings that should be interpreted as attributes/qualifiers instead of identifiers.
 
bool BinPackArguments
 If false, a function call's arguments will either be all on the same line or will have one line each.
 
bool BinPackParameters
 If false, a function declaration's or function definition's parameters will either all be on the same line or will have one line each.
 
BitFieldColonSpacingStyle BitFieldColonSpacing
 The BitFieldColonSpacingStyle to use for bitfields.
 
std::optional< unsignedBracedInitializerIndentWidth
 The number of columns to use to indent the contents of braced init lists.
 
BraceWrappingFlags BraceWrapping
 Control of individual brace wrapping cases.
 
AttributeBreakingStyle BreakAfterAttributes
 Break after a group of C++11 attributes before a function declaration/definition name.
 
bool BreakArrays
 If true, clang-format will always break after a Json array [ otherwise it will scan until the closing ] to determine if it should add newlines between elements (prettier compatible).
 
BinaryOperatorStyle BreakBeforeBinaryOperators
 The way to wrap binary operators.
 
BraceBreakingStyle BreakBeforeBraces
 The brace breaking style to use.
 
BreakBeforeConceptDeclarationsStyle BreakBeforeConceptDeclarations
 The concept declaration style to use.
 
BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon
 The inline ASM colon style to use.
 
bool BreakBeforeTernaryOperators
 If true, ternary operators will be placed after line breaks.
 
BreakConstructorInitializersStyle BreakConstructorInitializers
 The break constructor initializers style to use.
 
bool BreakAfterJavaFieldAnnotations
 Break after each annotation on a field in Java files.
 
bool BreakStringLiterals
 Allow breaking string literals when formatting.
 
unsigned ColumnLimit
 The column limit.
 
std::string CommentPragmas
 A regular expression that describes comments with special meaning, which should not be split into lines or otherwise changed.
 
BreakInheritanceListStyle BreakInheritanceList
 The inheritance list style to use.
 
bool CompactNamespaces
 If true, consecutive namespace declarations will be on the same line.
 
unsigned ConstructorInitializerIndentWidth
 This option is deprecated.
 
unsigned ContinuationIndentWidth
 Indent width for line continuations.
 
bool Cpp11BracedListStyle
 If true, format braced lists as best suited for C++11 braced lists.
 
bool DerivePointerAlignment
 This option is deprecated.
 
bool DisableFormat
 Disables formatting completely.
 
EmptyLineAfterAccessModifierStyle EmptyLineAfterAccessModifier
 Defines when to put an empty line after access modifiers.
 
EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier
 Defines in which cases to put empty line before access modifiers.
 
bool ExperimentalAutoDetectBinPacking
 If true, clang-format detects whether function calls and definitions are formatted with one parameter per line.
 
bool FixNamespaceComments
 If true, clang-format adds missing namespace end comments for namespaces and fixes invalid existing ones.
 
std::vector< std::string > ForEachMacros
 A vector of macros that should be interpreted as foreach loops instead of as function calls.
 
tooling::IncludeStyle IncludeStyle
 
std::vector< std::string > IfMacros
 A vector of macros that should be interpreted as conditionals instead of as function calls.
 
bool IndentAccessModifiers
 Specify whether access modifiers should have their own indentation level.
 
bool IndentCaseBlocks
 Indent case label blocks one level from the case label.
 
bool IndentCaseLabels
 Indent case labels one level from the switch statement.
 
bool IndentGotoLabels
 Indent goto labels.
 
IndentExternBlockStyle IndentExternBlock
 IndentExternBlockStyle is the type of indenting of extern blocks.
 
PPDirectiveIndentStyle IndentPPDirectives
 The preprocessor directive indenting style to use.
 
bool IndentRequiresClause
 Indent the requires clause in a template.
 
unsigned IndentWidth
 The number of columns to use for indentation.
 
bool IndentWrappedFunctionNames
 Indent if a function definition or declaration is wrapped after the type.
 
bool InsertBraces
 Insert braces after control statements (if, else, for, do, and while) in C++ unless the control statements are inside macro definitions or the braces would enclose preprocessor directives.
 
bool InsertNewlineAtEOF
 Insert a newline at end of file if missing.
 
TrailingCommaStyle InsertTrailingCommas
 If set to TCS_Wrapped will insert trailing commas in container literals (arrays and objects) that wrap across multiple lines.
 
IntegerLiteralSeparatorStyle IntegerLiteralSeparator
 Format integer literal separators (' for C++ and _ for C#, Java, and JavaScript).
 
std::vector< std::string > JavaImportGroups
 A vector of prefixes ordered by the desired groups for Java imports.
 
JavaScriptQuoteStyle JavaScriptQuotes
 The JavaScriptQuoteStyle to use for JavaScript strings.
 
bool JavaScriptWrapImports
 Whether to wrap JavaScript import/export statements.
 
bool KeepEmptyLinesAtTheStartOfBlocks
 If true, the empty line at the start of blocks is kept.
 
LambdaBodyIndentationKind LambdaBodyIndentation
 The indentation style of lambda bodies.
 
LanguageKind Language
 Language, this format style is targeted at.
 
LineEndingStyle LineEnding
 Line ending style (\n or \r\n) to use.
 
std::string MacroBlockBegin
 A regular expression matching macros that start a block.
 
std::string MacroBlockEnd
 A regular expression matching macros that end a block.
 
std::vector< std::string > Macros
 A list of macros of the form <definition>=<expansion> .
 
unsigned MaxEmptyLinesToKeep
 The maximum number of consecutive empty lines to keep.
 
NamespaceIndentationKind NamespaceIndentation
 The indentation used for namespaces.
 
std::vector< std::string > NamespaceMacros
 A vector of macros which are used to open namespace blocks.
 
BinPackStyle ObjCBinPackProtocolList
 Controls bin-packing Objective-C protocol conformance list items into as few lines as possible when they go over ColumnLimit.
 
unsigned ObjCBlockIndentWidth
 The number of characters to use for indentation of ObjC blocks.
 
bool ObjCBreakBeforeNestedBlockParam
 Break parameters list into lines when there is nested block parameters in a function call.
 
bool ObjCSpaceAfterProperty
 Add a space after @property in Objective-C, i.e.
 
bool ObjCSpaceBeforeProtocolList
 Add a space in front of an Objective-C protocol list, i.e.
 
PackConstructorInitializersStyle PackConstructorInitializers
 The pack constructor initializers style to use.
 
unsigned PenaltyBreakAssignment
 The penalty for breaking around an assignment operator.
 
unsigned PenaltyBreakBeforeFirstCallParameter
 The penalty for breaking a function call after call(.
 
unsigned PenaltyBreakComment
 The penalty for each line break introduced inside a comment.
 
unsigned PenaltyBreakFirstLessLess
 The penalty for breaking before the first <<.
 
unsigned PenaltyBreakOpenParenthesis
 The penalty for breaking after (.
 
unsigned PenaltyBreakString
 The penalty for each line break introduced inside a string literal.
 
unsigned PenaltyBreakTemplateDeclaration
 The penalty for breaking after template declaration.
 
unsigned PenaltyExcessCharacter
 The penalty for each character outside of the column limit.
 
unsigned PenaltyIndentedWhitespace
 Penalty for each character of whitespace indentation (counted relative to leading non-whitespace column).
 
unsigned PenaltyReturnTypeOnItsOwnLine
 Penalty for putting the return type of a function onto its own line.
 
PointerAlignmentStyle PointerAlignment
 Pointer and reference alignment style.
 
int PPIndentWidth
 The number of columns to use for indentation of preprocessor statements.
 
QualifierAlignmentStyle QualifierAlignment
 Different ways to arrange specifiers and qualifiers (e.g.
 
std::vector< std::string > QualifierOrder
 The order in which the qualifiers appear.
 
std::vector< RawStringFormatRawStringFormats
 Defines hints for detecting supported languages code blocks in raw strings.
 
ReferenceAlignmentStyle ReferenceAlignment
 Reference alignment style (overrides PointerAlignment for references).
 
bool ReflowComments
 If true, clang-format will attempt to re-flow comments.
 
bool RemoveBracesLLVM
 Remove optional braces of control statements (if, else, for, and while) in C++ according to the LLVM coding style.
 
bool RemoveSemicolon
 Remove semicolons after the closing brace of a non-empty function.
 
RequiresClausePositionStyle RequiresClausePosition
 The position of the requires clause.
 
RequiresExpressionIndentationKind RequiresExpressionIndentation
 The indentation used for requires expression bodies.
 
SeparateDefinitionStyle SeparateDefinitionBlocks
 Specifies the use of empty lines to separate definition blocks, including classes, structs, enums, and functions.
 
unsigned ShortNamespaceLines
 The maximal number of unwrapped lines that a short namespace spans.
 
SortIncludesOptions SortIncludes
 Controls if and how clang-format will sort #includes.
 
SortJavaStaticImportOptions SortJavaStaticImport
 When sorting Java imports, by default static imports are placed before non-static imports.
 
SortUsingDeclarationsOptions SortUsingDeclarations
 Controls if and how clang-format will sort using declarations.
 
bool SpaceAfterCStyleCast
 If true, a space is inserted after C style casts.
 
bool SpaceAfterLogicalNot
 If true, a space is inserted after the logical not operator (!).
 
bool SpaceAfterTemplateKeyword
 If true, a space will be inserted after the 'template' keyword.
 
SpaceAroundPointerQualifiersStyle SpaceAroundPointerQualifiers
 Defines in which cases to put a space before or after pointer qualifiers.
 
bool SpaceBeforeAssignmentOperators
 If false, spaces will be removed before assignment operators.
 
bool SpaceBeforeCaseColon
 If false, spaces will be removed before case colon.
 
bool SpaceBeforeCpp11BracedList
 If true, a space will be inserted before a C++11 braced list used to initialize an object (after the preceding identifier or type).
 
bool SpaceBeforeCtorInitializerColon
 If false, spaces will be removed before constructor initializer colon.
 
bool SpaceBeforeInheritanceColon
 If false, spaces will be removed before inheritance colon.
 
bool SpaceBeforeJsonColon
 If true, a space will be added before a JSON colon.
 
SpaceBeforeParensStyle SpaceBeforeParens
 Defines in which cases to put a space before opening parentheses.
 
SpaceBeforeParensCustom SpaceBeforeParensOptions
 Control of individual space before parentheses.
 
bool SpaceBeforeSquareBrackets
 If true, spaces will be before [.
 
bool SpaceBeforeRangeBasedForLoopColon
 If false, spaces will be removed before range-based for loop colon.
 
bool SpaceInEmptyBlock
 If true, spaces will be inserted into {}.
 
bool SpaceInEmptyParentheses
 If true, spaces may be inserted into ().
 
unsigned SpacesBeforeTrailingComments
 The number of spaces before trailing line comments (// - comments).
 
SpacesInAnglesStyle SpacesInAngles
 The SpacesInAnglesStyle to use for template argument lists.
 
bool SpacesInConditionalStatement
 If true, spaces will be inserted around if/for/switch/while conditions.
 
bool SpacesInContainerLiterals
 If true, spaces are inserted inside container literals (e.g.
 
bool SpacesInCStyleCastParentheses
 If true, spaces may be inserted into C style casts.
 
SpacesInLineComment SpacesInLineCommentPrefix
 How many spaces are allowed at the start of a line comment.
 
bool SpacesInParentheses
 If true, spaces will be inserted after ( and before ).
 
bool SpacesInSquareBrackets
 If true, spaces will be inserted after [ and before ].
 
LanguageStandard Standard
 Parse and format C++ constructs compatible with this standard.
 
std::vector< std::string > StatementAttributeLikeMacros
 Macros which are ignored in front of a statement, as if they were an attribute.
 
std::vector< std::string > StatementMacros
 A vector of macros that should be interpreted as complete statements.
 
unsigned TabWidth
 The number of columns used for tab stops.
 
std::vector< std::string > TypenameMacros
 A vector of macros that should be interpreted as type declarations instead of as function calls.
 
UseTabStyle UseTab
 The way to use tab characters in the resulting file.
 
bool VerilogBreakBetweenInstancePorts
 For Verilog, put each port on its own line in module instantiations.
 
std::vector< std::string > WhitespaceSensitiveMacros
 A vector of macros which are whitespace-sensitive and should not be touched.
 

Friends

std::error_code parseConfiguration (llvm::MemoryBufferRef Config, FormatStyle *Style, bool AllowUnknownOptions, llvm::SourceMgr::DiagHandlerTy DiagHandler, void *DiagHandlerCtxt)
 Parse configuration from YAML-formatted text.
 

Detailed Description

The FormatStyle is used to configure the formatting to follow specific guidelines.

Definition at line 55 of file Format.h.

Member Enumeration Documentation

◆ ArrayInitializerAlignmentStyle

Different style for aligning array initializers.

Enumerator
AIAS_Left 

Align array column and left justify the columns e.g.:

struct test demo[] =
{
{56, 23, "hello"},
{-1, 93463, "world"},
{7, 5, "!!" }
};
AIAS_Right 

Align array column and right justify the columns e.g.:

struct test demo[] =
{
{56, 23, "hello"},
{-1, 93463, "world"},
{ 7, 5, "!!"}
};
AIAS_None 

Don't align array initializer columns.

Definition at line 109 of file Format.h.

◆ AttributeBreakingStyle

Different ways to break after attributes.

Enumerator
ABS_Always 

Always break after attributes.

[[nodiscard]]
inline int f();
[[gnu::const]] [[nodiscard]]
int g();
ABS_Leave 

Leave the line breaking after attributes as is.

[[nodiscard]] inline int f();
[[gnu::const]] [[nodiscard]]
int g();
ABS_Never 

Never break after attributes.

[[nodiscard]] inline int f();
[[gnu::const]] [[nodiscard]] int g();

Definition at line 1259 of file Format.h.

◆ BinaryOperatorStyle

The style of breaking before or after binary operators.

Enumerator
BOS_None 

Break after operators.

LooooooooooongType loooooooooooooooooooooongVariable =
someLooooooooooooooooongFunction();
bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
ccccccccccccccccccccccccccccccccccccccccc;
BOS_NonAssignment 

Break before operators that aren't assignments.

LooooooooooongType loooooooooooooooooooooongVariable =
someLooooooooooooooooongFunction();
bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
== aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
&& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> ccccccccccccccccccccccccccccccccccccccccc;
BOS_All 

Break before operators.

LooooooooooongType loooooooooooooooooooooongVariable
= someLooooooooooooooooongFunction();
bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
== aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
&& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> ccccccccccccccccccccccccccccccccccccccccc;

Definition at line 1317 of file Format.h.

◆ BinPackStyle

The style of wrapping parameters on the same line (bin-packed) or on one line each.

Enumerator
BPS_Auto 

Automatically determine parameter bin-packing behavior.

BPS_Always 

Always bin-pack parameters.

BPS_Never 

Never bin-pack parameters.

Definition at line 1307 of file Format.h.

◆ BitFieldColonSpacingStyle

Styles for adding spacing around : in bitfield definitions.

Enumerator
BFCS_Both 

Add one space on each side of the :

unsigned bf : 2;
BFCS_None 

Add no space around the : (except when needed for AlignConsecutiveBitFields).

unsigned bf:2;
BFCS_Before 

Add space before the : only.

unsigned bf :2;
BFCS_After 

Add space after the : only (space may be added before if needed for AlignConsecutiveBitFields).

unsigned bf: 2;

Definition at line 919 of file Format.h.

◆ BraceBreakingStyle

Different ways to attach braces to their surrounding context.

Enumerator
BS_Attach 

Always attach braces to surrounding context.

namespace N {
enum E {
E1,
E2,
};
class C {
public:
C();
};
bool baz(int i) {
try {
do {
switch (i) {
case 1: {
foobar();
break;
}
default: {
break;
}
}
} while (--i);
return true;
} catch (...) {
handleError();
return false;
}
}
void foo(bool b) {
if (b) {
baz(2);
} else {
baz(5);
}
}
void bar() { foo(true); }
} // namespace N
__device__ __2f16 b
BS_Linux 

Like Attach, but break before braces on function, namespace and class definitions.

namespace N
{
enum E {
E1,
E2,
};
class C
{
public:
C();
};
bool baz(int i)
{
try {
do {
switch (i) {
case 1: {
foobar();
break;
}
default: {
break;
}
}
} while (--i);
return true;
} catch (...) {
handleError();
return false;
}
}
void foo(bool b)
{
if (b) {
baz(2);
} else {
baz(5);
}
}
void bar() { foo(true); }
} // namespace N
BS_Mozilla 

Like Attach, but break before braces on enum, function, and record definitions.

namespace N {
enum E
{
E1,
E2,
};
class C
{
public:
C();
};
bool baz(int i)
{
try {
do {
switch (i) {
case 1: {
foobar();
break;
}
default: {
break;
}
}
} while (--i);
return true;
} catch (...) {
handleError();
return false;
}
}
void foo(bool b)
{
if (b) {
baz(2);
} else {
baz(5);
}
}
void bar() { foo(true); }
} // namespace N
BS_Stroustrup 

Like Attach, but break before function definitions, catch, and else.

namespace N {
enum E {
E1,
E2,
};
class C {
public:
C();
};
bool baz(int i)
{
try {
do {
switch (i) {
case 1: {
foobar();
break;
}
default: {
break;
}
}
} while (--i);
return true;
}
catch (...) {
handleError();
return false;
}
}
void foo(bool b)
{
if (b) {
baz(2);
}
else {
baz(5);
}
}
void bar() { foo(true); }
} // namespace N
BS_Allman 

Always break before braces.

namespace N
{
enum E
{
E1,
E2,
};
class C
{
public:
C();
};
bool baz(int i)
{
try
{
do
{
switch (i)
{
case 1:
{
foobar();
break;
}
default:
{
break;
}
}
} while (--i);
return true;
}
catch (...)
{
handleError();
return false;
}
}
void foo(bool b)
{
if (b)
{
baz(2);
}
else
{
baz(5);
}
}
void bar() { foo(true); }
} // namespace N
BS_Whitesmiths 

Like Allman but always indent braces and line up code with braces.

namespace N
{
enum E
{
E1,
E2,
};
class C
{
public:
C();
};
bool baz(int i)
{
try
{
do
{
switch (i)
{
case 1:
{
foobar();
break;
}
default:
{
break;
}
}
} while (--i);
return true;
}
catch (...)
{
handleError();
return false;
}
}
void foo(bool b)
{
if (b)
{
baz(2);
}
else
{
baz(5);
}
}
void bar() { foo(true); }
} // namespace N
BS_GNU 

Always break before braces and add an extra level of indentation to braces of control statements, not to those of class, function or other definitions.

namespace N
{
enum E
{
E1,
E2,
};
class C
{
public:
C();
};
bool baz(int i)
{
try
{
do
{
switch (i)
{
case 1:
{
foobar();
break;
}
default:
{
break;
}
}
}
while (--i);
return true;
}
catch (...)
{
handleError();
return false;
}
}
void foo(bool b)
{
if (b)
{
baz(2);
}
else
{
baz(5);
}
}
void bar() { foo(true); }
} // namespace N
BS_WebKit 

Like Attach, but break before functions.

namespace N {
enum E {
E1,
E2,
};
class C {
public:
C();
};
bool baz(int i)
{
try {
do {
switch (i) {
case 1: {
foobar();
break;
}
default: {
break;
}
}
} while (--i);
return true;
} catch (...) {
handleError();
return false;
}
}
void foo(bool b)
{
if (b) {
baz(2);
} else {
baz(5);
}
}
void bar() { foo(true); }
} // namespace N
BS_Custom 

Configure each individual brace in BraceWrapping.

Definition at line 1361 of file Format.h.

◆ BraceWrappingAfterControlStatementStyle

Different ways to wrap braces after control statements.

Enumerator
BWACS_Never 

Never wrap braces after a control statement.

if (foo()) {
} else {
}
for (int i = 0; i < 10; ++i) {
}
BWACS_MultiLine 

Only wrap braces after a multi-line control statement.

if (foo && bar &&
baz)
{
quux();
}
while (foo || bar) {
}
BWACS_Always 

Always wrap braces after a control statement.

if (foo())
{
} else
{}
for (int i = 0; i < 10; ++i)
{}

Definition at line 981 of file Format.h.

◆ BracketAlignmentStyle

Different styles for aligning after open brackets.

Enumerator
BAS_Align 

Align parameters on the open bracket, e.g.:

someLongFunction(argument1,
argument2);
BAS_DontAlign 

Don't align, instead use ContinuationIndentWidth, e.g.:

someLongFunction(argument1,
argument2);
BAS_AlwaysBreak 

Always break after an open bracket, if the parameters don't fit on a single line, e.g.:

someLongFunction(
argument1, argument2);
BAS_BlockIndent 

Always break after an open bracket, if the parameters don't fit on a single line.

Closing brackets will be placed on a new line. E.g.:

someLongFunction(
argument1, argument2
)
Warning
Note: This currently only applies to parentheses. \endwarning

Definition at line 66 of file Format.h.

◆ BreakBeforeConceptDeclarationsStyle

Different ways to break before concept declarations.

Enumerator
BBCDS_Never 

Keep the template declaration line together with concept.

template <typename T> concept C = ...;
@ C
Languages that the frontend can parse and compile.
BBCDS_Allowed 

Breaking between template declaration and concept is allowed.

The actual behavior depends on the content and line breaking rules and penalties.

BBCDS_Always 

Always break before concept, putting it in the line after the template declaration.

template <typename T>
concept C = ...;

Definition at line 1796 of file Format.h.

◆ BreakBeforeInlineASMColonStyle

Different ways to break ASM parameters.

Enumerator
BBIAS_Never 

No break before inline ASM colon.

asm volatile("string", : : val);
BBIAS_OnlyMultiline 

Break before inline ASM colon if the line length is longer than column limit.

asm volatile("string", : : val);
asm("cmoveq %1, %2, %[result]"
: [result] "=r"(result)
: "r"(test), "r"(new), "[result]"(old));
BBIAS_Always 

Always break before inline ASM colon.

asm volatile("string",
:
: val);

Definition at line 1820 of file Format.h.

◆ BreakConstructorInitializersStyle

Different ways to break initializers.

Enumerator
BCIS_BeforeColon 

Break constructor initializers before the colon and after the commas.

Constructor()
: initializer1(),
initializer2()
BCIS_BeforeComma 

Break constructor initializers before the colon and commas, and align the commas with the colon.

Constructor()
: initializer1()
, initializer2()
BCIS_AfterColon 

Break constructor initializers after the colon and commas.

Constructor() :
initializer1(),
initializer2()

Definition at line 1864 of file Format.h.

◆ BreakInheritanceListStyle

Different ways to break inheritance list.

Enumerator
BILS_BeforeColon 

Break inheritance list before the colon and after the commas.

class Foo
: Base1,
Base2
{};
BILS_BeforeComma 

Break inheritance list before the colon and commas, and align the commas with the colon.

class Foo
: Base1
, Base2
{};
BILS_AfterColon 

Break inheritance list after the colon and commas.

class Foo :
Base1,
Base2
{};
BILS_AfterComma 

Break inheritance list only after the commas.

class Foo : Base1,
Base2
{};

Definition at line 1936 of file Format.h.

◆ BreakTemplateDeclarationsStyle

Different ways to break after the template declaration.

Enumerator
BTDS_No 

Do not force break before declaration.

PenaltyBreakTemplateDeclaration is taken into account.

template <typename T> T foo() {
}
template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
int bbbbbbbbbbbbbbbbbbbbb) {
}
BTDS_MultiLine 

Force break after template declaration only when the following declaration spans multiple lines.

template <typename T> T foo() {
}
template <typename T>
T foo(int aaaaaaaaaaaaaaaaaaaaa,
int bbbbbbbbbbbbbbbbbbbbb) {
}
BTDS_Yes 

Always break after template declaration.

template <typename T>
T foo() {
}
template <typename T>
T foo(int aaaaaaaaaaaaaaaaaaaaa,
int bbbbbbbbbbbbbbbbbbbbb) {
}

Definition at line 826 of file Format.h.

◆ DefinitionReturnTypeBreakingStyle

Different ways to break after the function definition return type.

This option is deprecated and is retained for backwards compatibility.

Enumerator
DRTBS_None 

Break after return type automatically.

PenaltyReturnTypeOnItsOwnLine is taken into account.

DRTBS_All 

Always break after the return type.

DRTBS_TopLevel 

Always break after the return types of top-level functions.

Definition at line 720 of file Format.h.

◆ EmptyLineAfterAccessModifierStyle

Different styles for empty line after access modifiers.

EmptyLineBeforeAccessModifier configuration handles the number of empty lines between two access modifiers.

Enumerator
ELAAMS_Never 

Remove all empty lines after access modifiers.

struct foo {
private:
int i;
protected:
int j;
/* comment */
public:
foo() {}
private:
protected:
};
ELAAMS_Leave 

Keep existing empty lines after access modifiers.

MaxEmptyLinesToKeep is applied instead.

ELAAMS_Always 

Always add empty line after access modifiers if there are none.

MaxEmptyLinesToKeep is applied also.

struct foo {
private:
int i;
protected:
int j;
/* comment */
public:
foo() {}
private:
protected:
};

Definition at line 2063 of file Format.h.

◆ EmptyLineBeforeAccessModifierStyle

Different styles for empty line before access modifiers.

Enumerator
ELBAMS_Never 

Remove all empty lines before access modifiers.

struct foo {
private:
int i;
protected:
int j;
/* comment */
public:
foo() {}
private:
protected:
};
ELBAMS_Leave 

Keep existing empty lines before access modifiers.

ELBAMS_LogicalBlock 

Add empty line only when access modifier starts a new logical block.

Logical block is a group of one or more member fields or functions.

struct foo {
private:
int i;
protected:
int j;
/* comment */
public:
foo() {}
private:
protected:
};
ELBAMS_Always 

Always add empty line before access modifiers unless access modifier is at the start of struct or class definition.

struct foo {
private:
int i;
protected:
int j;
/* comment */
public:
foo() {}
private:
protected:
};

Definition at line 2112 of file Format.h.

◆ EscapedNewlineAlignmentStyle

Different styles for aligning escaped newlines.

Enumerator
ENAS_DontAlign 

Don't align escaped newlines.

#define A \
int aaaa; \
int b; \
int dddddddddd;
ENAS_Left 

Align escaped newlines as far left as possible.

true:
#define A \
int aaaa; \
int b; \
int dddddddddd;
false:
ENAS_Right 

Align escaped newlines in the right-most column.

#define A \
int aaaa; \
int b; \
int dddddddddd;

Definition at line 300 of file Format.h.

◆ IndentExternBlockStyle

Indents extern blocks.

Enumerator
IEBS_AfterExternBlock 

Backwards compatible with AfterExternBlock's indenting.

IndentExternBlock: AfterExternBlock
extern "C"
{
void foo();
}
bool AfterExternBlock
Wrap extern blocks.
Definition: Format.h:1140
BraceWrappingFlags BraceWrapping
Control of individual brace wrapping cases.
Definition: Format.h:1256
IndentExternBlockStyle IndentExternBlock
IndentExternBlockStyle is the type of indenting of extern blocks.
Definition: Format.h:2368
IndentExternBlock: AfterExternBlock
extern "C" {
void foo();
}
IEBS_NoIndent 

Does not indent extern blocks.

extern "C" {
void foo();
}
IEBS_Indent 

Indents extern blocks.

extern "C" {
void foo();
}

Definition at line 2331 of file Format.h.

◆ JavaScriptQuoteStyle

Quotation styles for JavaScript strings.

Does not affect template strings.

Enumerator
JSQS_Leave 

Leave string quotes as they are.

string1 = "foo";
string2 = 'bar';
JSQS_Single 

Always use single quotes.

string1 = 'foo';
string2 = 'bar';
JSQS_Double 

Always use double quotes.

string1 = "foo";
string2 = "bar";

Definition at line 2636 of file Format.h.

◆ LambdaBodyIndentationKind

Indentation logic for lambda bodies.

Enumerator
LBI_Signature 

Align lambda body relative to the lambda signature.

This is the default.

someMethod(
[](SomeReallyLongLambdaSignatureArgument foo) {
return;
});
LBI_OuterScope 

Align lambda body relative to the indentation level of the outer scope the lambda signature resides in.

someMethod(
[](SomeReallyLongLambdaSignatureArgument foo) {
return;
});
someMethod(someOtherMethod(
[](SomeReallyLongLambdaSignatureArgument foo) {
return;
}));

Definition at line 2690 of file Format.h.

◆ LanguageKind

Supported languages.

When stored in a configuration file, specifies the language, that the configuration targets. When passed to the reformat() function, enables syntax features specific to the language.

Enumerator
LK_None 

Do not use.

LK_Cpp 

Should be used for C, C++.

LK_CSharp 

Should be used for C#.

LK_Java 

Should be used for Java.

LK_JavaScript 

Should be used for JavaScript.

LK_Json 

Should be used for JSON.

LK_ObjC 

Should be used for Objective-C, Objective-C++.

LK_Proto 

Should be used for Protocol Buffers (https://developers.google.com/protocol-buffers/).

LK_TableGen 

Should be used for TableGen code.

LK_TextProto 

Should be used for Protocol Buffer messages in text format (https://developers.google.com/protocol-buffers/).

LK_Verilog 

Should be used for Verilog and SystemVerilog.

https://standards.ieee.org/ieee/1800/6700/ https://sci-hub.st/10.1109/IEEESTD.2018.8299595

Definition at line 2728 of file Format.h.

◆ LanguageStandard

Supported language standards for parsing and formatting C++ constructs.

Latest: vector<set<int>>
c++03 vs. vector<set<int> >
__device__ __2f16 float c

The correct way to spell a specific language version is e.g. c++11. The historical aliases Cpp03 and Cpp11 are deprecated.

Enumerator
LS_Cpp03 

Parse and format as C++03.

Cpp03 is a deprecated alias for c++03

LS_Cpp11 

Parse and format as C++11.

LS_Cpp14 

Parse and format as C++14.

LS_Cpp17 

Parse and format as C++17.

LS_Cpp20 

Parse and format as C++20.

LS_Latest 

Parse and format using the latest supported language version.

Cpp11 is a deprecated alias for Latest

LS_Auto 

Automatic detection based on the input.

Definition at line 4155 of file Format.h.

◆ LineEndingStyle

Line ending style.

Enumerator
LE_LF 

Use \n.

LE_CRLF 

Use \r\n.

LE_DeriveLF 

Use \n unless the input has more lines ending in \r\n.

LE_DeriveCRLF 

Use \r\n unless the input has more lines ending in \n.

Definition at line 2768 of file Format.h.

◆ NamespaceIndentationKind

Different ways to indent namespace contents.

Enumerator
NI_None 

Don't indent in namespaces.

namespace out {
int i;
namespace in {
int i;
}
}
NI_Inner 

Indent only in inner namespaces (nested in other namespaces).

namespace out {
int i;
namespace in {
int i;
}
}
NI_All 

Indent in all namespaces.

namespace out {
int i;
namespace in {
int i;
}
}

Definition at line 2871 of file Format.h.

◆ OperandAlignmentStyle

Different styles for aligning operands.

Enumerator
OAS_DontAlign 

Do not align operands of binary and ternary expressions.

The wrapped lines are indented ContinuationIndentWidth spaces from the start of the line.

OAS_Align 

Horizontally align operands of binary and ternary expressions.

Specifically, this aligns operands of a single expression that needs
to be split over multiple lines, e.g.:
\code
  int aaa = bbbbbbbbbbbbbbb +
            ccccccccccccccc;
\endcode

When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is
aligned with the operand on the first line.
\code
  int aaa = bbbbbbbbbbbbbbb
            + ccccccccccccccc;
\endcode 
OAS_AlignAfterOperator 

Horizontally align operands of binary and ternary expressions.

This is similar to ``AO_Align``, except when
``BreakBeforeBinaryOperators`` is set, the operator is un-indented so
that the wrapped operand is aligned with the operand on the first line.
\code
  int aaa = bbbbbbbbbbbbbbb
          + ccccccccccccccc;
\endcode 

Definition at line 335 of file Format.h.

◆ PackConstructorInitializersStyle

Different ways to try to fit all constructor initializers on a line.

Enumerator
PCIS_Never 

Always put each constructor initializer on its own line.

Constructor()
: a(),
b()
PCIS_BinPack 

Bin-pack constructor initializers.

Constructor()
: aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(),
cccccccccccccccccccc()
PCIS_CurrentLine 

Put all constructor initializers on the current line if they fit.

Otherwise, put each one on its own line.

Constructor() : a(), b()
Constructor()
: aaaaaaaaaaaaaaaaaaaa(),
bbbbbbbbbbbbbbbbbbbb(),
ddddddddddddd()
PCIS_NextLine 

Same as PCIS_CurrentLine except that if all constructor initializers do not fit on the current line, try to fit them on the next line.

Constructor() : a(), b()
Constructor()
: aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
Constructor()
: aaaaaaaaaaaaaaaaaaaa(),
bbbbbbbbbbbbbbbbbbbb(),
cccccccccccccccccccc()
PCIS_NextLineOnly 

Put all constructor initializers on the next line if they fit.

Otherwise, put each one on its own line.

Constructor()
: a(), b()
Constructor()
: aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
Constructor()
: aaaaaaaaaaaaaaaaaaaa(),
bbbbbbbbbbbbbbbbbbbb(),
cccccccccccccccccccc()

Definition at line 3000 of file Format.h.

◆ PointerAlignmentStyle

The &, && and * alignment style.

Enumerator
PAS_Left 

Align pointer to the left.

int* a;
PAS_Right 

Align pointer to the right.

int *a;
PAS_Middle 

Align pointer in the middle.

int * a;

Definition at line 3103 of file Format.h.

◆ PPDirectiveIndentStyle

Options for indenting preprocessor directives.

Enumerator
PPDIS_None 

Does not indent any directives.

#if FOO
#if BAR
#include <foo>
#endif
#endif
PPDIS_AfterHash 

Indents directives after the hash.

#if FOO
# if BAR
# include <foo>
# endif
#endif
PPDIS_BeforeHash 

Indents directives before the hash.

#if FOO
#if BAR
#include <foo>
#endif
#endif

Definition at line 2371 of file Format.h.

◆ QualifierAlignmentStyle

Different specifiers and qualifiers alignment styles.

Enumerator
QAS_Leave 

Don't change specifiers/qualifiers to either Left or Right alignment (default).

int const a;
const int *a;
QAS_Left 

Change specifiers/qualifiers to be left-aligned.

const int a;
const int *a;
QAS_Right 

Change specifiers/qualifiers to be right-aligned.

int const a;
int const *a;
QAS_Custom 

Change specifiers/qualifiers to be aligned based on QualifierOrder.

With:

QualifierOrder: ['inline', 'static', 'type', 'const']
int const a;
int const *a;

Definition at line 3141 of file Format.h.

◆ ReferenceAlignmentStyle

The & and && alignment style.

Enumerator
RAS_Pointer 

Align reference like PointerAlignment.

RAS_Left 

Align reference to the left.

int& a;
RAS_Right 

Align reference to the right.

int &a;
RAS_Middle 

Align reference in the middle.

int & a;

Definition at line 3270 of file Format.h.

◆ RequiresClausePositionStyle

The possible positions for the requires clause.

The IndentRequires option is only used if the requires is put on the start of a line.

Enumerator
RCPS_OwnLine 

Always put the requires clause on its own line.

template <typename T>
requires C<T>
struct Foo {...
template <typename T>
requires C<T>
void bar(T t) {...
template <typename T>
void baz(T t)
requires C<T>
{...
RCPS_WithPreceding 

Try to put the clause together with the preceding part of a declaration.

For class templates: stick to the template declaration. For function templates: stick to the template declaration. For function declaration followed by a requires clause: stick to the parameter list.

template <typename T> requires C<T>
struct Foo {...
template <typename T> requires C<T>
void bar(T t) {...
template <typename T>
void baz(T t) requires C<T>
{...
RCPS_WithFollowing 

Try to put the requires clause together with the class or function declaration.

template <typename T>
requires C<T> struct Foo {...
template <typename T>
requires C<T> void bar(T t) {...
template <typename T>
void baz(T t)
requires C<T> {...
RCPS_SingleLine 

Try to put everything in the same line if possible.

Otherwise normal line breaking rules take over.

// Fitting:
template <typename T> requires C<T> struct Foo {...
template <typename T> requires C<T> void bar(T t) {...
template <typename T> void bar(T t) requires C<T> {...
// Not fitting, one possible example:
template <typename LongName>
requires C<LongName>
struct Foo {...
template <typename LongName>
requires C<LongName>
void bar(LongName ln) {
template <typename LongName>
void bar(LongName ln)
requires C<LongName> {

Definition at line 3388 of file Format.h.

◆ RequiresExpressionIndentationKind

Indentation logic for requires expression bodies.

Enumerator
REI_OuterScope 

Align requires expression body relative to the indentation level of the outer scope the requires expression resides in.

This is the default.

template <typename T>
concept C = requires(T t) {
...
}
REI_Keyword 

Align requires expression body relative to the requires keyword.

template <typename T>
concept C = requires(T t) {
...
}

Definition at line 3467 of file Format.h.

◆ ReturnTypeBreakingStyle

Different ways to break after the function definition or declaration return type.

Enumerator
RTBS_None 

Break after return type automatically.

PenaltyReturnTypeOnItsOwnLine is taken into account.

class A {
int f() { return 0; };
};
int f();
int f() { return 1; }
RTBS_All 

Always break after the return type.

class A {
int
f() {
return 0;
};
};
int
f();
int
f() {
return 1;
}
RTBS_TopLevel 

Always break after the return types of top-level functions.

class A {
int f() { return 0; };
};
int
f();
int
f() {
return 1;
}
RTBS_AllDefinitions 

Always break after the return type of function definitions.

class A {
int
f() {
return 0;
};
};
int f();
int
f() {
return 1;
}
RTBS_TopLevelDefinitions 

Always break after the return type of top-level definitions.

class A {
int f() { return 0; };
};
int f();
int
f() {
return 1;
}

Definition at line 732 of file Format.h.

◆ SeparateDefinitionStyle

The style if definition blocks should be separated.

Enumerator
SDS_Leave 

Leave definition blocks as they are.

SDS_Always 

Insert an empty line between definition blocks.

SDS_Never 

Remove any empty line between definition blocks.

Definition at line 3493 of file Format.h.

◆ ShortBlockStyle

Different styles for merging short blocks containing at most one statement.

Enumerator
SBS_Never 

Never merge blocks into a single line.

while (true) {
}
while (true) {
continue;
}
SBS_Empty 

Only merge empty blocks.

while (true) {}
while (true) {
continue;
}
SBS_Always 

Always merge short blocks into a single line.

while (true) {}
while (true) { continue; }

Definition at line 496 of file Format.h.

◆ ShortFunctionStyle

Different styles for merging short functions containing at most one statement.

Enumerator
SFS_None 

Never merge functions into a single line.

SFS_InlineOnly 

Only merge functions defined inside a class.

Same as "inline", except it does not implies "empty": i.e. top level empty functions are not merged either.

class Foo {
void f() { foo(); }
};
void f() {
foo();
}
void f() {
}
SFS_Empty 

Only merge empty functions.

void f() {}
void f2() {
bar2();
}
SFS_Inline 

Only merge functions defined inside a class.

Implies "empty".

class Foo {
void f() { foo(); }
};
void f() {
foo();
}
void f() {}
SFS_All 

Merge all functions fitting on a single line.

class Foo {
void f() { foo(); }
};
void f() { bar(); }

Definition at line 557 of file Format.h.

◆ ShortIfStyle

Different styles for handling short if statements.

Enumerator
SIS_Never 

Never put short ifs on the same line.

if (a)
return;
if (b)
return;
else
return;
if (c)
return;
else {
return;
}
SIS_WithoutElse 

Put short ifs on the same line only if there is no else statement.

if (a) return;
if (b)
return;
else
return;
if (c)
return;
else {
return;
}
SIS_OnlyFirstIf 

Put short ifs, but not else ifs nor else statements, on the same line.

if (a) return;
if (b) return;
else if (b)
return;
else
return;
if (c) return;
else {
return;
}
SIS_AllIfsAndElse 

Always put short ifs, else ifs and else statements on the same line.

if (a) return;
if (b) return;
else return;
if (c) return;
else {
return;
}

Definition at line 609 of file Format.h.

◆ ShortLambdaStyle

Different styles for merging short lambdas containing at most one statement.

Enumerator
SLS_None 

Never merge lambdas into a single line.

SLS_Empty 

Only merge empty lambdas.

auto lambda = [](int a) {};
auto lambda2 = [](int a) {
return a;
};
SLS_Inline 

Merge lambda into a single line if the lambda is argument of a function.

auto lambda = [](int x, int y) {
return x < y;
};
sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
SLS_All 

Merge all lambdas fitting on a single line.

auto lambda = [](int a) {};
auto lambda2 = [](int a) { return a; };

Definition at line 681 of file Format.h.

◆ SortIncludesOptions

Include sorting options.

Enumerator
SI_Never 

Includes are never sorted.

#include "B/A.h"
#include "A/B.h"
#include "a/b.h"
#include "A/b.h"
#include "B/a.h"
SI_CaseSensitive 

Includes are sorted in an ASCIIbetical or case sensitive fashion.

#include "A/B.h"
#include "A/b.h"
#include "B/A.h"
#include "B/a.h"
#include "a/b.h"
SI_CaseInsensitive 

Includes are sorted in an alphabetical or case insensitive fashion.

#include "A/B.h"
#include "A/b.h"
#include "a/b.h"
#include "B/A.h"
#include "B/a.h"

Definition at line 3573 of file Format.h.

◆ SortJavaStaticImportOptions

Position for Java Static imports.

Enumerator
SJSIO_Before 

Static imports are placed before non-static imports.

import static org.example.function1;
import org.example.ClassA;
SJSIO_After 

Static imports are placed after non-static imports.

import org.example.ClassA;
import static org.example.function1;

Definition at line 3608 of file Format.h.

◆ SortUsingDeclarationsOptions

Using declaration sorting options.

Enumerator
SUD_Never 

Using declarations are never sorted.

using std::chrono::duration_cast;
using std::move;
using boost::regex;
using boost::regex_constants::icase;
using std::string;
SUD_Lexicographic 

Using declarations are sorted in the order defined as follows: Split the strings by "::" and discard any initial empty strings.

Sort the lists of names lexicographically, and within those groups, names are in case-insensitive lexicographic order.

using boost::regex;
using boost::regex_constants::icase;
using std::chrono::duration_cast;
using std::move;
using std::string;
SUD_LexicographicNumeric 

Using declarations are sorted in the order defined as follows: Split the strings by "::" and discard any initial empty strings.

The last element of each list is a non-namespace name; all others are namespace names. Sort the lists of names lexicographically, where the sort order of individual names is that all non-namespace names come before all namespace names, and within those groups, names are in case-insensitive lexicographic order.

using boost::regex;
using boost::regex_constants::icase;
using std::move;
using std::string;
using std::chrono::duration_cast;

Definition at line 3632 of file Format.h.

◆ SpaceAroundPointerQualifiersStyle

Different ways to put a space before opening parentheses.

Enumerator
SAPQ_Default 

Don't ensure spaces around pointer qualifiers and use PointerAlignment instead.

void* const* x = NULL; vs. void *const *x = NULL;
#define NULL
Definition: stddef.h:89
PointerAlignmentStyle PointerAlignment
Pointer and reference alignment style.
Definition: Format.h:3123
SAPQ_Before 

Ensure that there is a space before pointer qualifiers.

void* const* x = NULL; vs. void * const *x = NULL;
SAPQ_After 

Ensure that there is a space after pointer qualifiers.

void* const * x = NULL; vs. void *const *x = NULL;
SAPQ_Both 

Ensure that there is a space both before and after pointer qualifiers.

void* const * x = NULL; vs. void * const *x = NULL;

Definition at line 3700 of file Format.h.

◆ SpaceBeforeParensStyle

Different ways to put a space before opening parentheses.

Enumerator
SBPO_Never 

Never put a space before opening parentheses.

void f() {
if(true) {
f();
}
}
SBPO_ControlStatements 

Put a space before opening parentheses only after control statement keywords (for/if/while...).

void f() {
if (true) {
f();
}
}
SBPO_ControlStatementsExceptControlMacros 

Same as SBPO_ControlStatements except this option doesn't apply to ForEach and If macros.

This is useful in projects where ForEach/If macros are treated as function calls instead of control statements. SBPO_ControlStatementsExceptForEachMacros remains an alias for backward compatibility.

void f() {
Q_FOREACH(...) {
f();
}
}
SBPO_NonEmptyParentheses 

Put a space before opening parentheses only if the parentheses are not empty i.e.

'()'

void() {
if (true) {
f();
g (x, y, z);
}
}
SBPO_Always 

Always put a space before opening parentheses, except when it's prohibited by the syntax rules (in function-like macro definitions) or when determined by other style rules (after unary operators, opening parentheses, etc.)

void f () {
if (true) {
f ();
}
}
SBPO_Custom 

Configure each individual space before parentheses in SpaceBeforeParensOptions.

Definition at line 3792 of file Format.h.

◆ SpacesInAnglesStyle

Styles for adding spacing after < and before `> in template argument lists.

Enumerator
SIAS_Never 

Remove spaces after < and before >.

static_cast<int>(arg);
std::function<void(int)> fct;
SIAS_Always 

Add spaces after < and before >.

static_cast< int >(arg);
std::function< void(int) > fct;
SIAS_Leave 

Keep a single space after < and before > if any spaces were present.

Option Standard: Cpp03 takes precedence.

Definition at line 4036 of file Format.h.

◆ TrailingCommaStyle

The style of inserting trailing commas into container literals.

Enumerator
TCS_None 

Do not insert trailing commas.

TCS_Wrapped 

Insert trailing commas in container literals that were wrapped over multiple lines.

Note that this is conceptually incompatible with bin-packing, because the trailing comma is used as an indicator that a container should be formatted one-per-line (i.e. not bin-packed). So inserting a trailing comma counteracts bin-packing.

Definition at line 2492 of file Format.h.

◆ TrailingCommentsAlignmentKinds

Enums for AlignTrailingComments.

Enumerator
TCAS_Leave 

Leave trailing comments as they are.

int a; // comment
int ab; // comment
int abc; // comment
int abcd; // comment
TCAS_Always 

Align trailing comments.

int a; // comment
int ab; // comment
int abc; // comment
int abcd; // comment
TCAS_Never 

Don't align trailing comments but other formatter applies.

int a; // comment
int ab; // comment
int abc; // comment
int abcd; // comment

Definition at line 374 of file Format.h.

◆ UseTabStyle

This option is deprecated.

See LF and CRLF of LineEnding.

Version
10 Different ways to use tab in formatting.
Enumerator
UT_Never 

Never use tab.

UT_ForIndentation 

Use tabs only for indentation.

UT_ForContinuationAndIndentation 

Fill all leading whitespace with tabs, and use spaces for alignment that appears within a line (e.g.

consecutive assignments and declarations).

UT_AlignWithSpaces 

Use tabs for line continuation and indentation, and spaces for alignment.

UT_Always 

Use tabs whenever we need to fill whitespace that spans at least from one tab stop to the next one.

Definition at line 4236 of file Format.h.

Member Function Documentation

◆ BuildStyleSetFromConfiguration()

static FormatStyleSet clang::format::FormatStyle::BuildStyleSetFromConfiguration ( const FormatStyle MainStyle,
const std::vector< FormatStyle > &  ConfigurationStyles 
)
static

◆ GetLanguageStyle()

std::optional< FormatStyle > clang::format::FormatStyle::GetLanguageStyle ( FormatStyle::LanguageKind  Language) const

◆ isCpp()

bool clang::format::FormatStyle::isCpp ( ) const
inline

◆ isCSharp()

bool clang::format::FormatStyle::isCSharp ( ) const
inline

◆ isJavaScript()

bool clang::format::FormatStyle::isJavaScript ( ) const
inline

◆ isJson()

bool clang::format::FormatStyle::isJson ( ) const
inline

Definition at line 2758 of file Format.h.

References LK_Json.

Referenced by clang::format::internal::reformat().

◆ isProto()

bool clang::format::FormatStyle::isProto ( ) const
inline

Definition at line 2761 of file Format.h.

References LK_Proto.

◆ isVerilog()

bool clang::format::FormatStyle::isVerilog ( ) const
inline

Definition at line 2760 of file Format.h.

References LK_Verilog.

◆ operator==()

bool clang::format::FormatStyle::operator== ( const FormatStyle R) const
inline

Definition at line 4287 of file Format.h.

References AccessModifierOffset, AlignAfterOpenBracket, AlignArrayOfStructures, AlignConsecutiveAssignments, AlignConsecutiveBitFields, AlignConsecutiveDeclarations, AlignConsecutiveMacros, AlignEscapedNewlines, AlignOperands, AlignTrailingComments, AllowAllArgumentsOnNextLine, AllowAllParametersOfDeclarationOnNextLine, AllowShortBlocksOnASingleLine, AllowShortCaseLabelsOnASingleLine, AllowShortEnumsOnASingleLine, AllowShortFunctionsOnASingleLine, AllowShortIfStatementsOnASingleLine, AllowShortLambdasOnASingleLine, AllowShortLoopsOnASingleLine, AlwaysBreakAfterReturnType, AlwaysBreakBeforeMultilineStrings, AlwaysBreakTemplateDeclarations, AttributeMacros, BinPackArguments, BinPackParameters, BitFieldColonSpacing, BracedInitializerIndentWidth, BreakAfterAttributes, BreakAfterJavaFieldAnnotations, BreakArrays, BreakBeforeBinaryOperators, BreakBeforeBraces, BreakBeforeConceptDeclarations, BreakBeforeInlineASMColon, BreakBeforeTernaryOperators, BreakConstructorInitializers, BreakInheritanceList, BreakStringLiterals, ColumnLimit, CommentPragmas, CompactNamespaces, ConstructorInitializerIndentWidth, ContinuationIndentWidth, Cpp11BracedListStyle, DerivePointerAlignment, DisableFormat, EmptyLineAfterAccessModifier, EmptyLineBeforeAccessModifier, ExperimentalAutoDetectBinPacking, FixNamespaceComments, ForEachMacros, clang::tooling::IncludeStyle::IncludeBlocks, clang::tooling::IncludeStyle::IncludeCategories, clang::tooling::IncludeStyle::IncludeIsMainRegex, clang::tooling::IncludeStyle::IncludeIsMainSourceRegex, IncludeStyle, IndentAccessModifiers, IndentCaseBlocks, IndentCaseLabels, IndentExternBlock, IndentGotoLabels, IndentPPDirectives, IndentRequiresClause, IndentWidth, IndentWrappedFunctionNames, InsertBraces, InsertNewlineAtEOF, IntegerLiteralSeparator, JavaImportGroups, JavaScriptQuotes, JavaScriptWrapImports, KeepEmptyLinesAtTheStartOfBlocks, LambdaBodyIndentation, Language, LineEnding, MacroBlockBegin, MacroBlockEnd, Macros, MaxEmptyLinesToKeep, clang::format::FormatStyle::SpacesInLineComment::Maximum, clang::format::FormatStyle::SpacesInLineComment::Minimum, NamespaceIndentation, NamespaceMacros, ObjCBinPackProtocolList, ObjCBlockIndentWidth, ObjCBreakBeforeNestedBlockParam, ObjCSpaceAfterProperty, ObjCSpaceBeforeProtocolList, PackConstructorInitializers, PenaltyBreakAssignment, PenaltyBreakBeforeFirstCallParameter, PenaltyBreakComment, PenaltyBreakFirstLessLess, PenaltyBreakOpenParenthesis, PenaltyBreakString, PenaltyBreakTemplateDeclaration, PenaltyExcessCharacter, PenaltyReturnTypeOnItsOwnLine, PointerAlignment, QualifierAlignment, QualifierOrder, RawStringFormats, ReferenceAlignment, RemoveBracesLLVM, RemoveSemicolon, RequiresClausePosition, RequiresExpressionIndentation, SeparateDefinitionBlocks, ShortNamespaceLines, SortIncludes, SortJavaStaticImport, SpaceAfterCStyleCast, SpaceAfterLogicalNot, SpaceAfterTemplateKeyword, SpaceAroundPointerQualifiers, SpaceBeforeAssignmentOperators, SpaceBeforeCaseColon, SpaceBeforeCpp11BracedList, SpaceBeforeCtorInitializerColon, SpaceBeforeInheritanceColon, SpaceBeforeJsonColon, SpaceBeforeParens, SpaceBeforeParensOptions, SpaceBeforeRangeBasedForLoopColon, SpaceBeforeSquareBrackets, SpaceInEmptyBlock, SpaceInEmptyParentheses, SpacesBeforeTrailingComments, SpacesInAngles, SpacesInConditionalStatement, SpacesInContainerLiterals, SpacesInCStyleCastParentheses, SpacesInLineCommentPrefix, SpacesInParentheses, SpacesInSquareBrackets, Standard, StatementAttributeLikeMacros, StatementMacros, TabWidth, TypenameMacros, UseTab, VerilogBreakBetweenInstancePorts, and WhitespaceSensitiveMacros.

Friends And Related Function Documentation

◆ parseConfiguration

std::error_code parseConfiguration ( llvm::MemoryBufferRef  Config,
FormatStyle Style,
bool  AllowUnknownOptions = false,
llvm::SourceMgr::DiagHandlerTy  DiagHandler = nullptr,
void *  DiagHandlerCtxt = nullptr 
)
friend

Parse configuration from YAML-formatted text.

Style->Language is used to get the base style, if the BasedOnStyle option is present.

The FormatStyleSet of Style is reset.

When BasedOnStyle is not present, options not present in the YAML document, are retained in Style.

If AllowUnknownOptions is true, no errors are emitted if unknown format options are occurred.

If set all diagnostics are emitted through the DiagHandler.

Definition at line 1871 of file Format.cpp.

Referenced by clang::format::getStyle(), and clang::format::loadAndParseConfigFile().

Member Data Documentation

◆ AccessModifierOffset

int clang::format::FormatStyle::AccessModifierOffset

The extra indent or outdent of access modifiers, e.g.

public:.

Version
3.3

Definition at line 63 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), clang::format::getWebKitStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ AlignAfterOpenBracket

BracketAlignmentStyle clang::format::FormatStyle::AlignAfterOpenBracket

If true, horizontally aligns arguments after an open bracket.

This applies to round brackets (parentheses), angle brackets and square brackets.

Version
3.8

Definition at line 106 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), clang::format::getWebKitStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), operator==(), and clang::format::CommaSeparatedList::precomputeFormattingInfos().

◆ AlignArrayOfStructures

ArrayInitializerAlignmentStyle clang::format::FormatStyle::AlignArrayOfStructures

if not None, when using initialization for an array of structs aligns the fields into columns.

NOTE: As of clang-format 15 this option only applied to arrays with equal number of columns per row.

Version
13

Definition at line 140 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ AlignConsecutiveAssignments

AlignConsecutiveStyle clang::format::FormatStyle::AlignConsecutiveAssignments

Style of aligning consecutive assignments.

Consecutive will result in formattings like:

int a = 1;
int somelongname = 2;
double c = 3;
Version
3.8

Definition at line 275 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ AlignConsecutiveBitFields

AlignConsecutiveStyle clang::format::FormatStyle::AlignConsecutiveBitFields

Style of aligning consecutive bit fields.

Consecutive will align the bitfield separators of consecutive lines. This will result in formattings like:

int aaaa : 1;
int b : 12;
int ccc : 8;
Version
11

Definition at line 286 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ AlignConsecutiveDeclarations

AlignConsecutiveStyle clang::format::FormatStyle::AlignConsecutiveDeclarations

Style of aligning consecutive declarations.

Consecutive will align the declaration names of consecutive lines. This will result in formattings like:

int aaaa = 12;
float b = 23;
std::string ccc;
Version
3.8

Definition at line 297 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ AlignConsecutiveMacros

AlignConsecutiveStyle clang::format::FormatStyle::AlignConsecutiveMacros

Style of aligning consecutive macro definitions.

Consecutive will result in formattings like:

#define SHORT_NAME 42
#define LONGER_NAME 0x007f
#define EVEN_LONGER_NAME (2)
#define foo(x) (x * x)
#define bar(y, z) (y + z)
Version
9

Definition at line 265 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ AlignEscapedNewlines

EscapedNewlineAlignmentStyle clang::format::FormatStyle::AlignEscapedNewlines

Options for aligning backslashes in escaped newlines.

Version
5

Definition at line 332 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ AlignOperands

OperandAlignmentStyle clang::format::FormatStyle::AlignOperands

If true, horizontally align operands of binary and ternary expressions.

Version
3.5

Definition at line 371 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), clang::format::getWebKitStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ AlignTrailingComments

TrailingCommentsAlignmentStyle clang::format::FormatStyle::AlignTrailingComments

Control of trailing comments.

NOTE: As of clang-format 16 this option is not a bool but can be set to the options. Conventional bool options still can be parsed as before.

# Example of usage:
AlignTrailingComments:
Kind: Always
OverEmptyLines: 2
Version
3.7

Definition at line 452 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), clang::format::getWebKitStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ AllowAllArgumentsOnNextLine

bool clang::format::FormatStyle::AllowAllArgumentsOnNextLine

If a function call or braced initializer list doesn't fit on a line, allow putting all arguments onto the next line, even if BinPackArguments is false.

true:
callFunction(
a, b, c, d);
false:
callFunction(a,
b,
c,
d);
Version
9

Definition at line 469 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ AllowAllParametersOfDeclarationOnNextLine

bool clang::format::FormatStyle::AllowAllParametersOfDeclarationOnNextLine

This option is deprecated.

See NextLine of PackConstructorInitializers.

Version
9 If the function declaration doesn't fit on a line, allow putting all parameters of a function declaration onto the next line even if BinPackParameters is false.
true:
void myFunction(
int a, int b, int c, int d, int e);
false:
void myFunction(int a,
int b,
int c,
int d,
int e);
3.3

Definition at line 492 of file Format.h.

Referenced by clang::format::getChromiumStyle(), clang::format::getLLVMStyle(), clang::format::getMozillaStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ AllowShortBlocksOnASingleLine

ShortBlockStyle clang::format::FormatStyle::AllowShortBlocksOnASingleLine

Dependent on the value, while (true) { continue; } can be put on a single line.

Version
3.5

Definition at line 525 of file Format.h.

Referenced by clang::format::getLLVMStyle(), clang::format::getWebKitStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ AllowShortCaseLabelsOnASingleLine

bool clang::format::FormatStyle::AllowShortCaseLabelsOnASingleLine

If true, short case labels will be contracted to a single line.

true: false:
switch (a) { vs. switch (a) {
case 1: x = 1; break; case 1:
case 2: return; x = 1;
} break;
case 2:
return;
}
Version
3.6

Definition at line 539 of file Format.h.

Referenced by clang::format::getLLVMStyle(), clang::format::getMicrosoftStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ AllowShortEnumsOnASingleLine

bool clang::format::FormatStyle::AllowShortEnumsOnASingleLine

Allow short enums on a single line.

true:
enum { A, B } myEnum;
false:
enum {
A,
B
} myEnum;
Version
11

Definition at line 553 of file Format.h.

Referenced by clang::format::getLLVMStyle(), clang::format::getMicrosoftStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ AllowShortFunctionsOnASingleLine

ShortFunctionStyle clang::format::FormatStyle::AllowShortFunctionsOnASingleLine

◆ AllowShortIfStatementsOnASingleLine

ShortIfStyle clang::format::FormatStyle::AllowShortIfStatementsOnASingleLine

Dependent on the value, if (a) return; can be put on a single line.

Version
3.3

Definition at line 677 of file Format.h.

Referenced by clang::format::getChromiumStyle(), clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), clang::format::getMicrosoftStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ AllowShortLambdasOnASingleLine

ShortLambdaStyle clang::format::FormatStyle::AllowShortLambdasOnASingleLine

Dependent on the value, auto lambda []() { return 0; } can be put on a single line.

Version
9

Definition at line 711 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ AllowShortLoopsOnASingleLine

bool clang::format::FormatStyle::AllowShortLoopsOnASingleLine

◆ AlwaysBreakAfterDefinitionReturnType

DefinitionReturnTypeBreakingStyle clang::format::FormatStyle::AlwaysBreakAfterDefinitionReturnType

The function definition return type breaking style to use.

This option is deprecated and is retained for backwards compatibility.

Version
3.7

Definition at line 804 of file Format.h.

Referenced by clang::format::getGNUStyle(), clang::format::getLLVMStyle(), clang::format::getMicrosoftStyle(), clang::format::getMozillaStyle(), and llvm::yaml::MappingTraits< FormatStyle >::mapping().

◆ AlwaysBreakAfterReturnType

ReturnTypeBreakingStyle clang::format::FormatStyle::AlwaysBreakAfterReturnType

◆ AlwaysBreakBeforeMultilineStrings

bool clang::format::FormatStyle::AlwaysBreakBeforeMultilineStrings

If true, always break before multiline string literals.

This flag is mean to make cases where there are multiple multiline strings in a file look more consistent. Thus, it will only take effect if wrapping the string at that point leads to it being indented ContinuationIndentWidth spaces from the start of the line.

true: false:
aaaa = vs. aaaa = "bbbb"
"bbbb" "cccc";
"cccc";
Version
3.4

Definition at line 823 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), clang::format::ContinuationIndenter::mustBreak(), and operator==().

◆ AlwaysBreakTemplateDeclarations

BreakTemplateDeclarationsStyle clang::format::FormatStyle::AlwaysBreakTemplateDeclarations

◆ AttributeMacros

std::vector<std::string> clang::format::FormatStyle::AttributeMacros

A vector of strings that should be interpreted as attributes/qualifiers instead of identifiers.

This can be useful for language extensions or static analyzer annotations.

For example:

x = (char *__capability)&y;
int function(void) __ununsed;
void only_writes_to_buffer(char *__output buffer);

In the .clang-format configuration file, this can be configured like:

AttributeMacros: ['__capability', '__output', '__ununsed']
Version
12

Definition at line 882 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ BinPackArguments

bool clang::format::FormatStyle::BinPackArguments

If false, a function call's arguments will either be all on the same line or will have one line each.

true:
void f() {
f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
}
false:
void f() {
f(aaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
}
Version
3.7

Definition at line 901 of file Format.h.

Referenced by clang::format::getLLVMStyle(), clang::format::getMozillaStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), operator==(), and clang::format::CommaSeparatedList::precomputeFormattingInfos().

◆ BinPackParameters

bool clang::format::FormatStyle::BinPackParameters

If false, a function declaration's or function definition's parameters will either all be on the same line or will have one line each.

true:
void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
false:
void f(int aaaaaaaaaaaaaaaaaaaa,
int aaaaaaaaaaaaaaaaaaaa,
int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
Version
3.7

Definition at line 916 of file Format.h.

Referenced by clang::format::getChromiumStyle(), clang::format::getLLVMStyle(), clang::format::getMozillaStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), clang::format::ContinuationIndenter::mustBreak(), and operator==().

◆ BitFieldColonSpacing

BitFieldColonSpacingStyle clang::format::FormatStyle::BitFieldColonSpacing

The BitFieldColonSpacingStyle to use for bitfields.

Version
12

Definition at line 945 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ BracedInitializerIndentWidth

std::optional<unsigned> clang::format::FormatStyle::BracedInitializerIndentWidth

The number of columns to use to indent the contents of braced init lists.

If unset, ContinuationIndentWidth is used.

void f() {
SomeClass c{
"foo",
"bar",
"baz",
};
auto s = SomeStruct{
.foo = "foo",
.bar = "bar",
.baz = "baz",
};
SomeArrayT a[3] = {
{
foo,
bar,
},
{
foo,
bar,
},
SomeArrayT{},
};
}
__device__ __2f16 float bool s
std::optional< unsigned > BracedInitializerIndentWidth
The number of columns to use to indent the contents of braced init lists.
Definition: Format.h:978
BracketAlignmentStyle AlignAfterOpenBracket
If true, horizontally aligns arguments after an open bracket.
Definition: Format.h:106
Version
17

Definition at line 978 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ BraceWrapping

BraceWrappingFlags clang::format::FormatStyle::BraceWrapping

Control of individual brace wrapping cases.

If BreakBeforeBraces is set to BS_Custom, use this to specify how each individual brace case should be handled. Otherwise, this is ignored.

# Example of usage:
BreakBeforeBraces: Custom
BraceWrapping:
AfterEnum: true
AfterStruct: false
SplitEmptyFunction: false
Version
3.8

Definition at line 1256 of file Format.h.

Referenced by clang::format::expandPresetsBraceWrapping(), clang::format::getLLVMStyle(), clang::format::getMicrosoftStyle(), clang::format::hasNestedBlockInlined(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), clang::format::ContinuationIndenter::mustBreak(), and clang::format::ShouldBreakBeforeBrace().

◆ BreakAfterAttributes

AttributeBreakingStyle clang::format::FormatStyle::BreakAfterAttributes

Break after a group of C++11 attributes before a function declaration/definition name.

Version
16

Definition at line 1286 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), clang::format::mustBreakAfterAttributes(), and operator==().

◆ BreakAfterJavaFieldAnnotations

bool clang::format::FormatStyle::BreakAfterJavaFieldAnnotations

Break after each annotation on a field in Java files.

true: false:
@Partial vs. @Partial @Mock DataLoad loader;
@Mock
DataLoad loader;
Version
3.8

Definition at line 1901 of file Format.h.

Referenced by clang::format::getChromiumStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ BreakArrays

bool clang::format::FormatStyle::BreakArrays

If true, clang-format will always break after a Json array [ otherwise it will scan until the closing ] to determine if it should add newlines between elements (prettier compatible).

NOTE: This is currently only for formatting JSON.

true: false:
[ vs. [1, 2, 3, 4]
1,
2,
3,
4
]
Version
16

Definition at line 1303 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ BreakBeforeBinaryOperators

BinaryOperatorStyle clang::format::FormatStyle::BreakBeforeBinaryOperators

◆ BreakBeforeBraces

BraceBreakingStyle clang::format::FormatStyle::BreakBeforeBraces

◆ BreakBeforeConceptDeclarations

BreakBeforeConceptDeclarationsStyle clang::format::FormatStyle::BreakBeforeConceptDeclarations

The concept declaration style to use.

Version
12

Definition at line 1817 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), clang::format::ContinuationIndenter::mustBreak(), and operator==().

◆ BreakBeforeInlineASMColon

BreakBeforeInlineASMColonStyle clang::format::FormatStyle::BreakBeforeInlineASMColon

The inline ASM colon style to use.

Version
16

Definition at line 1846 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), clang::format::ContinuationIndenter::mustBreak(), and operator==().

◆ BreakBeforeTernaryOperators

bool clang::format::FormatStyle::BreakBeforeTernaryOperators

If true, ternary operators will be placed after line breaks.

true:
veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
? firstValue
: SecondValueVeryVeryVeryVeryLong;
false:
veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
firstValue :
SecondValueVeryVeryVeryVeryLong;
Version
3.7

Definition at line 1861 of file Format.h.

Referenced by clang::format::getGNUStyle(), clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), clang::format::ContinuationIndenter::mustBreak(), and operator==().

◆ BreakConstructorInitializers

BreakConstructorInitializersStyle clang::format::FormatStyle::BreakConstructorInitializers

◆ BreakInheritanceList

BreakInheritanceListStyle clang::format::FormatStyle::BreakInheritanceList

◆ BreakStringLiterals

bool clang::format::FormatStyle::BreakStringLiterals

Allow breaking string literals when formatting.

true:
const char* x = "veryVeryVeryVeryVeryVe"
"ryVeryVeryVeryVeryVery"
"VeryLongString";
false:
const char* x =
"veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
Version
3.9

Definition at line 1915 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ ColumnLimit

unsigned clang::format::FormatStyle::ColumnLimit

◆ CommentPragmas

std::string clang::format::FormatStyle::CommentPragmas

A regular expression that describes comments with special meaning, which should not be split into lines or otherwise changed.

// CommentPragmas: '^ FOOBAR pragma:'
// Will leave the following line unaffected
#include <vector> // FOOBAR pragma: keep
Version
3.7

Definition at line 1933 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ CompactNamespaces

bool clang::format::FormatStyle::CompactNamespaces

If true, consecutive namespace declarations will be on the same line.

If false, each namespace is declared on a new line.

true:
namespace Foo { namespace Bar {
}}
false:
namespace Foo {
namespace Bar {
}
}

If it does not fit on a single line, the overflowing namespaces get wrapped:

namespace Foo { namespace Bar {
namespace Extra {
}}}
Version
5

Definition at line 1997 of file Format.h.

Referenced by clang::format::NamespaceEndCommentsFixer::analyze(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ ConstructorInitializerIndentWidth

unsigned clang::format::FormatStyle::ConstructorInitializerIndentWidth

This option is deprecated.

See CurrentLine of PackConstructorInitializers.

Version
3.7 The number of characters to use for indentation of constructor initializer lists as well as inheritance lists.
3.7

Definition at line 2007 of file Format.h.

Referenced by clang::format::getLLVMStyle(), clang::format::getMozillaStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ ContinuationIndentWidth

unsigned clang::format::FormatStyle::ContinuationIndentWidth

Indent width for line continuations.

int i = // VeryVeryVeryVeryVeryLongComment
longFunction( // Again a long comment
arg);
unsigned ContinuationIndentWidth
Indent width for line continuations.
Definition: Format.h:2018
Version
3.7

Definition at line 2018 of file Format.h.

Referenced by clang::format::getChromiumStyle(), clang::format::BreakableBlockComment::getContentIndent(), clang::format::getLLVMStyle(), clang::format::getMozillaStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), clang::format::ContinuationIndenter::mustBreak(), and operator==().

◆ Cpp11BracedListStyle

bool clang::format::FormatStyle::Cpp11BracedListStyle

If true, format braced lists as best suited for C++11 braced lists.

Important differences:

  • No spaces inside the braced list.
  • No line break before the closing brace.
  • Indentation with the continuation indent, not with the block indent.

Fundamentally, C++11 braced lists are formatted exactly like function calls would be formatted in their place. If the braced list follows a name (e.g. a type or variable name), clang-format formats as if the {} were the parentheses of a function call with that name. If there is no name, a zero-length name is assumed.

true: false:
vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
Version
3.4

Definition at line 2041 of file Format.h.

Referenced by clang::format::getGNUStyle(), clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), clang::format::getMozillaStyle(), clang::format::getWebKitStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), operator==(), and clang::format::CommaSeparatedList::precomputeFormattingInfos().

◆ DerivePointerAlignment

bool clang::format::FormatStyle::DerivePointerAlignment

This option is deprecated.

See DeriveLF and DeriveCRLF of LineEnding.

Version
10 If true, analyze the formatted file for the most common alignment of & and *. Pointer and reference alignment styles are going to be updated according to the preferences found in the file. PointerAlignment is then used only as fallback.
3.7

Definition at line 2054 of file Format.h.

Referenced by clang::format::getChromiumStyle(), clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ DisableFormat

bool clang::format::FormatStyle::DisableFormat

◆ EmptyLineAfterAccessModifier

EmptyLineAfterAccessModifierStyle clang::format::FormatStyle::EmptyLineAfterAccessModifier

Defines when to put an empty line after access modifiers.

EmptyLineBeforeAccessModifier configuration handles the number of empty lines between two access modifiers.

Version
13

Definition at line 2109 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), clang::format::newlinesBeforeLine(), and operator==().

◆ EmptyLineBeforeAccessModifier

EmptyLineBeforeAccessModifierStyle clang::format::FormatStyle::EmptyLineBeforeAccessModifier

Defines in which cases to put empty line before access modifiers.

Version
12

Definition at line 2172 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), clang::format::newlinesBeforeLine(), and operator==().

◆ ExperimentalAutoDetectBinPacking

bool clang::format::FormatStyle::ExperimentalAutoDetectBinPacking

If true, clang-format detects whether function calls and definitions are formatted with one parameter per line.

Each call can be bin-packed, one-per-line or inconclusive. If it is inconclusive, e.g. completely on one line, but a decision needs to be made, clang-format analyzes whether there are other bin-packed cases in the input file and act accordingly.

NOTE: This is an experimental flag, that might go away or be renamed. Do not use this in config files, etc. Use at your own risk.

Version
3.7

Definition at line 2185 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ FixNamespaceComments

bool clang::format::FormatStyle::FixNamespaceComments

If true, clang-format adds missing namespace end comments for namespaces and fixes invalid existing ones.

This doesn't affect short namespaces, which are controlled by ShortNamespaceLines.

true: false:
namespace longNamespace { vs. namespace longNamespace {
void foo(); void foo();
void bar(); void bar();
} // namespace a }
namespace shortNamespace { namespace shortNamespace {
void baz(); void baz();
} }
Version
5

Definition at line 2201 of file Format.h.

Referenced by clang::format::getGNUStyle(), clang::format::getLLVMStyle(), clang::format::getMozillaStyle(), clang::format::getWebKitStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), operator==(), and clang::format::internal::reformat().

◆ ForEachMacros

std::vector<std::string> clang::format::FormatStyle::ForEachMacros

A vector of macros that should be interpreted as foreach loops instead of as function calls.

These are expected to be macros of the form:

FOREACH(<variable-declaration>, ...)
<loop-body>

In the .clang-format configuration file, this can be configured like:

ForEachMacros: ['RANGES_FOR', 'FOREACH']

For example: BOOST_FOREACH.

Version
3.7

Definition at line 2219 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ IfMacros

std::vector<std::string> clang::format::FormatStyle::IfMacros

A vector of macros that should be interpreted as conditionals instead of as function calls.

These are expected to be macros of the form:

IF(...)
<conditional-body>
else IF(...)
<conditional-body>

In the .clang-format configuration file, this can be configured like:

IfMacros: ['IF']

For example: KJ_IF_MAYBE <https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes>_

Version
13

Definition at line 2242 of file Format.h.

Referenced by clang::format::getLLVMStyle(), and llvm::yaml::MappingTraits< FormatStyle >::mapping().

◆ IncludeStyle

tooling::IncludeStyle clang::format::FormatStyle::IncludeStyle

◆ IndentAccessModifiers

bool clang::format::FormatStyle::IndentAccessModifiers

Specify whether access modifiers should have their own indentation level.

When false, access modifiers are indented (or outdented) relative to the record members, respecting the AccessModifierOffset. Record members are indented one level below the record. When true, access modifiers get their own indentation level. As a consequence, record members are always indented 2 levels below the record, regardless of the access modifier presence. Value of the AccessModifierOffset is ignored.

false: true:
class C { vs. class C {
class D { class D {
void bar(); void bar();
protected: protected:
D(); D();
}; };
public: public:
C(); C();
}; };
void foo() { void foo() {
return 1; return 1;
} }
Version
13

Definition at line 2269 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ IndentCaseBlocks

bool clang::format::FormatStyle::IndentCaseBlocks

Indent case label blocks one level from the case label.

When false, the block following the case label uses the same indentation level as for the case label, treating the case label the same as an if-statement. When true, the block gets indented as a scope block.

false: true:
switch (fool) { vs. switch (fool) {
case 1: { case 1:
bar(); {
} break; bar();
default: { }
plop(); break;
} default:
} {
plop();
}
}
Version
11

Definition at line 2292 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ IndentCaseLabels

bool clang::format::FormatStyle::IndentCaseLabels

Indent case labels one level from the switch statement.

When false, use the same indentation level as for the switch statement. Switch statement body is always indented one level more than case labels (except the first block following the case label, which itself indents the code - unless IndentCaseBlocks is enabled).

false: true:
switch (fool) { vs. switch (fool) {
case 1: case 1:
bar(); bar();
break; break;
default: default:
plop(); plop();
} }
Version
3.3

Definition at line 2311 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), clang::format::getMozillaStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ IndentExternBlock

IndentExternBlockStyle clang::format::FormatStyle::IndentExternBlock

IndentExternBlockStyle is the type of indenting of extern blocks.

Version
11

Definition at line 2368 of file Format.h.

Referenced by clang::format::expandPresetsBraceWrapping(), clang::format::getLLVMStyle(), clang::format::getMicrosoftStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ IndentGotoLabels

bool clang::format::FormatStyle::IndentGotoLabels

Indent goto labels.

When false, goto labels are flushed left.

true: false:
int f() { vs. int f() {
if (foo()) { if (foo()) {
label1: label1:
bar(); bar();
} }
label2: label2:
return 1; return 1;
} }
Version
10

Definition at line 2328 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ IndentPPDirectives

PPDirectiveIndentStyle clang::format::FormatStyle::IndentPPDirectives

The preprocessor directive indenting style to use.

Version
6

Definition at line 2403 of file Format.h.

Referenced by clang::format::ContinuationIndenter::getInitialState(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ IndentRequiresClause

bool clang::format::FormatStyle::IndentRequiresClause

Indent the requires clause in a template.

This only applies when RequiresClausePosition is OwnLine, or WithFollowing.

In clang-format 12, 13 and 14 it was named IndentRequires.

true:
template <typename It>
requires Iterator<It>
void sort(It begin, It end) {
//....
}
false:
template <typename It>
requires Iterator<It>
void sort(It begin, It end) {
//....
}
Version
15

Definition at line 2425 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), operator==(), and clang::format::internal::reformat().

◆ IndentWidth

unsigned clang::format::FormatStyle::IndentWidth

The number of columns to use for indentation.

void f() {
someFunction();
if (true, false) {
f();
}
}
unsigned IndentWidth
The number of columns to use for indentation.
Definition: Format.h:2439
Version
3.7

Definition at line 2439 of file Format.h.

Referenced by clang::format::getChromiumStyle(), clang::format::getLLVMStyle(), clang::format::getMicrosoftStyle(), clang::format::getWebKitStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ IndentWrappedFunctionNames

bool clang::format::FormatStyle::IndentWrappedFunctionNames

Indent if a function definition or declaration is wrapped after the type.

true:
LoooooooooooooooooooooooooooooooooooooooongReturnType
LoooooooooooooooooooooooooooooooongFunctionDeclaration();
false:
LoooooooooooooooooooooooooooooooooooooooongReturnType
LoooooooooooooooooooooooooooooooongFunctionDeclaration();
Version
3.7

Definition at line 2453 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), operator==(), and clang::format::shouldIndentWrappedSelectorName().

◆ InheritsParentConfig

bool clang::format::FormatStyle::InheritsParentConfig

◆ InsertBraces

bool clang::format::FormatStyle::InsertBraces

Insert braces after control statements (if, else, for, do, and while) in C++ unless the control statements are inside macro definitions or the braces would enclose preprocessor directives.

Warning
Setting this option to true could lead to incorrect code formatting due to clang-format's lack of complete semantic information. As such, extra care should be taken to review code changes made by this option. \endwarning
false: true:
if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) {
handleFunctionDecl(D); handleFunctionDecl(D);
else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) {
handleVarDecl(D); handleVarDecl(D);
else } else {
return; return;
}
while (i--) vs. while (i--) {
for (auto *A : D.attrs()) for (auto *A : D.attrs()) {
handleAttr(A); handleAttr(A);
}
}
do vs. do {
--i; --i;
while (i); } while (i);
Version
15

Definition at line 2485 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), operator==(), and clang::format::internal::reformat().

◆ InsertNewlineAtEOF

bool clang::format::FormatStyle::InsertNewlineAtEOF

Insert a newline at end of file if missing.

Version
16

Definition at line 2489 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ InsertTrailingCommas

TrailingCommaStyle clang::format::FormatStyle::InsertTrailingCommas

If set to TCS_Wrapped will insert trailing commas in container literals (arrays and objects) that wrap across multiple lines.

It is currently only available for JavaScript and disabled by default TCS_None. InsertTrailingCommas cannot be used together with BinPackArguments as inserting the comma disables bin-packing.

TSC_Wrapped:
const someArray = [
aaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaa,
// ^ inserted
]
Version
11

Definition at line 2519 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and clang::format::internal::reformat().

◆ IntegerLiteralSeparator

IntegerLiteralSeparatorStyle clang::format::FormatStyle::IntegerLiteralSeparator

Format integer literal separators (' for C++ and _ for C#, Java, and JavaScript).

Version
16

Definition at line 2598 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ JavaImportGroups

std::vector<std::string> clang::format::FormatStyle::JavaImportGroups

A vector of prefixes ordered by the desired groups for Java imports.

One group's prefix can be a subset of another - the longest prefix is always matched. Within a group, the imports are ordered lexicographically. Static imports are grouped separately and follow the same group rules. By default, static imports are placed before non-static imports, but this behavior is changed by another option, SortJavaStaticImport.

In the .clang-format configuration file, this can be configured like in the following yaml example. This will result in imports being formatted as in the Java example below.

JavaImportGroups: ['com.example', 'com', 'org']
import static com.example.function1;
import static com.test.function2;
import static org.example.function3;
import com.example.ClassA;
import com.example.Test;
import com.example.a.ClassB;
import com.test.ClassC;
import org.example.ClassD;
Version
8

Definition at line 2632 of file Format.h.

Referenced by clang::format::findJavaImportGroup(), clang::format::getChromiumStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), operator==(), and clang::format::sortJavaImports().

◆ JavaScriptQuotes

JavaScriptQuoteStyle clang::format::FormatStyle::JavaScriptQuotes

The JavaScriptQuoteStyle to use for JavaScript strings.

Version
3.9

Definition at line 2659 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), operator==(), and clang::format::internal::reformat().

◆ JavaScriptWrapImports

bool clang::format::FormatStyle::JavaScriptWrapImports

Whether to wrap JavaScript import/export statements.

true:
import {
VeryLongImportsAreAnnoying,
VeryLongImportsAreAnnoying,
VeryLongImportsAreAnnoying,
} from 'some/module.js'
false:
import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
Version
3.9

Definition at line 2675 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ KeepEmptyLinesAtTheStartOfBlocks

bool clang::format::FormatStyle::KeepEmptyLinesAtTheStartOfBlocks

If true, the empty line at the start of blocks is kept.

true: false:
if (foo) { vs. if (foo) {
bar();
bar(); }
}
Version
3.7

Definition at line 2687 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), clang::format::newlinesBeforeLine(), and operator==().

◆ LambdaBodyIndentation

LambdaBodyIndentationKind clang::format::FormatStyle::LambdaBodyIndentation

The indentation style of lambda bodies.

Signature (the default) causes the lambda body to be indented one additional level relative to the indentation level of the signature. OuterScope forces the lambda body to be indented one additional level relative to the parent scope containing the lambda signature.

Version
13

Definition at line 2721 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ Language

LanguageKind clang::format::FormatStyle::Language

◆ LineEnding

LineEndingStyle clang::format::FormatStyle::LineEnding

Line ending style (\n or \r\n) to use.

Version
16

Definition at line 2781 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ MacroBlockBegin

std::string clang::format::FormatStyle::MacroBlockBegin

A regular expression matching macros that start a block.

# With:
MacroBlockBegin: "^NS_MAP_BEGIN|\
NS_TABLE_HEAD$"
NS_MAP_END|\
NS_TABLE_.*_END$"
NS_MAP_BEGIN
foo();
NS_MAP_END
NS_TABLE_HEAD
bar();
NS_TABLE_FOO_END
# Without:
NS_MAP_BEGIN
foo();
NS_MAP_END
NS_TABLE_HEAD
bar();
NS_TABLE_FOO_END
std::string MacroBlockBegin
A regular expression matching macros that start a block.
Definition: Format.h:2810
std::string MacroBlockEnd
A regular expression matching macros that end a block.
Definition: Format.h:2814
Version
3.7

Definition at line 2810 of file Format.h.

Referenced by llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ MacroBlockEnd

std::string clang::format::FormatStyle::MacroBlockEnd

A regular expression matching macros that end a block.

Version
3.7

Definition at line 2814 of file Format.h.

Referenced by llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ Macros

std::vector<std::string> clang::format::FormatStyle::Macros

A list of macros of the form <definition>=<expansion> .

Code will be parsed with macros expanded, in order to determine how to interpret and format the macro arguments.

For example, the code:

A(a*b);

will usually be interpreted as a call to a function A, and the multiplication expression will be formatted as a * b.

If we specify the macro definition:

Macros:
- A(x)=x

the code will now be parsed as a declaration of the variable b of type a*, and formatted as a* b (depending on pointer-binding rules).

Features and restrictions:

  • Both function-like macros and object-like macros are supported.
  • Macro arguments must be used exactly once in the expansion.
  • No recursive expansion; macros referencing other macros will be ignored.
  • Overloading by arity is supported: for example, given the macro definitions A=x, A()=y, A(a)=a
A; -> x;
A(); -> y;
A(z); -> z;
A(a, b); // will not be expanded.
Version
17.0

Definition at line 2854 of file Format.h.

Referenced by llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ MaxEmptyLinesToKeep

unsigned clang::format::FormatStyle::MaxEmptyLinesToKeep

The maximum number of consecutive empty lines to keep.

int f() { int f() {
int = 1; int i = 1;
i = foo();
i = foo(); return i;
}
return i;
}
unsigned MaxEmptyLinesToKeep
The maximum number of consecutive empty lines to keep.
Definition: Format.h:2868
Version
3.7

Definition at line 2868 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), clang::format::newlinesBeforeLine(), and operator==().

◆ NamespaceIndentation

NamespaceIndentationKind clang::format::FormatStyle::NamespaceIndentation

◆ NamespaceMacros

std::vector<std::string> clang::format::FormatStyle::NamespaceMacros

A vector of macros which are used to open namespace blocks.

These are expected to be macros of the form:

NAMESPACE(<namespace-name>, ...) {
<namespace-content>
}

For example: TESTSUITE

Version
9

Definition at line 2919 of file Format.h.

Referenced by llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ ObjCBinPackProtocolList

BinPackStyle clang::format::FormatStyle::ObjCBinPackProtocolList

Controls bin-packing Objective-C protocol conformance list items into as few lines as possible when they go over ColumnLimit.

If Auto (the default), delegates to the value in BinPackParameters. If that is true, bin-packs Objective-C protocol conformance list items into as few lines as possible whenever they go over ColumnLimit.

If Always, always bin-packs Objective-C protocol conformance list items into as few lines as possible whenever they go over ColumnLimit.

If Never, lays out Objective-C protocol conformance list items onto individual lines whenever they go over ColumnLimit.

Always (or Auto, if BinPackParameters=true):
@interface ccccccccccccc () <
ccccccccccccc, ccccccccccccc,
ccccccccccccc, ccccccccccccc> {
}
Never (or Auto, if BinPackParameters=false):
@interface ddddddddddddd () <
ddddddddddddd,
ddddddddddddd,
ddddddddddddd,
ddddddddddddd> {
}
Version
7

Definition at line 2952 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ ObjCBlockIndentWidth

unsigned clang::format::FormatStyle::ObjCBlockIndentWidth

The number of characters to use for indentation of ObjC blocks.

ObjCBlockIndentWidth: 4
[operation setCompletionBlock:^{
[self onOperationDone];
}];
Version
3.7

Definition at line 2963 of file Format.h.

Referenced by clang::format::getLLVMStyle(), clang::format::getWebKitStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ ObjCBreakBeforeNestedBlockParam

bool clang::format::FormatStyle::ObjCBreakBeforeNestedBlockParam

Break parameters list into lines when there is nested block parameters in a function call.

false:
- (void)_aMethod
{
[self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
*u, NSNumber *v) {
u = c;
}]
}
true:
- (void)_aMethod
{
[self.test1 t:self
w:self
callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
u = c;
}]
}
do v
Definition: arm_acle.h:76
Version
11

Definition at line 2987 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), clang::format::ContinuationIndenter::mustBreak(), and operator==().

◆ ObjCSpaceAfterProperty

bool clang::format::FormatStyle::ObjCSpaceAfterProperty

Add a space after @property in Objective-C, i.e.

use @property (readonly) instead of @property(readonly).

Version
3.7

Definition at line 2992 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), clang::format::getMozillaStyle(), clang::format::getWebKitStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ ObjCSpaceBeforeProtocolList

bool clang::format::FormatStyle::ObjCSpaceBeforeProtocolList

Add a space in front of an Objective-C protocol list, i.e.

use Foo <Protocol> instead of Foo<Protocol>.

Version
3.7

Definition at line 2997 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), clang::format::getMozillaStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ PackConstructorInitializers

PackConstructorInitializersStyle clang::format::FormatStyle::PackConstructorInitializers

The pack constructor initializers style to use.

Version
14

Definition at line 3059 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ PenaltyBreakAssignment

unsigned clang::format::FormatStyle::PenaltyBreakAssignment

The penalty for breaking around an assignment operator.

Version
5

Definition at line 3063 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ PenaltyBreakBeforeFirstCallParameter

unsigned clang::format::FormatStyle::PenaltyBreakBeforeFirstCallParameter

The penalty for breaking a function call after call(.

Version
3.7

Definition at line 3067 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ PenaltyBreakComment

unsigned clang::format::FormatStyle::PenaltyBreakComment

The penalty for each line break introduced inside a comment.

Version
3.7

Definition at line 3071 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ PenaltyBreakFirstLessLess

unsigned clang::format::FormatStyle::PenaltyBreakFirstLessLess

The penalty for breaking before the first <<.

Version
3.7

Definition at line 3075 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ PenaltyBreakOpenParenthesis

unsigned clang::format::FormatStyle::PenaltyBreakOpenParenthesis

The penalty for breaking after (.

Version
14

Definition at line 3079 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ PenaltyBreakString

unsigned clang::format::FormatStyle::PenaltyBreakString

The penalty for each line break introduced inside a string literal.

Version
3.7

Definition at line 3083 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ PenaltyBreakTemplateDeclaration

unsigned clang::format::FormatStyle::PenaltyBreakTemplateDeclaration

The penalty for breaking after template declaration.

Version
7

Definition at line 3087 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ PenaltyExcessCharacter

unsigned clang::format::FormatStyle::PenaltyExcessCharacter

The penalty for each character outside of the column limit.

Version
3.7

Definition at line 3091 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ PenaltyIndentedWhitespace

unsigned clang::format::FormatStyle::PenaltyIndentedWhitespace

Penalty for each character of whitespace indentation (counted relative to leading non-whitespace column).

Version
12

Definition at line 3096 of file Format.h.

Referenced by clang::format::getLLVMStyle(), and llvm::yaml::MappingTraits< FormatStyle >::mapping().

◆ PenaltyReturnTypeOnItsOwnLine

unsigned clang::format::FormatStyle::PenaltyReturnTypeOnItsOwnLine

Penalty for putting the return type of a function onto its own line.

Version
3.7

Definition at line 3100 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), clang::format::getMicrosoftStyle(), clang::format::getMozillaStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ PointerAlignment

PointerAlignmentStyle clang::format::FormatStyle::PointerAlignment

◆ PPIndentWidth

int clang::format::FormatStyle::PPIndentWidth

The number of columns to use for indentation of preprocessor statements.

When set to -1 (default) IndentWidth is used also for preprocessor statements.

#ifdef __linux__
# define FOO
#else
# define BAR
#endif
int PPIndentWidth
The number of columns to use for indentation of preprocessor statements.
Definition: Format.h:3138
Version
13

Definition at line 3138 of file Format.h.

Referenced by clang::format::getLLVMStyle(), and llvm::yaml::MappingTraits< FormatStyle >::mapping().

◆ QualifierAlignment

QualifierAlignmentStyle clang::format::FormatStyle::QualifierAlignment

Different ways to arrange specifiers and qualifiers (e.g.

const/volatile).

Warning
Setting QualifierAlignment to something other than Leave, COULD lead to incorrect code formatting due to incorrect decisions made due to clang-formats lack of complete semantic information. As such extra care should be taken to review code changes made by the use of this option. \endwarning
Version
14

Definition at line 3184 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), operator==(), and clang::format::internal::reformat().

◆ QualifierOrder

std::vector<std::string> clang::format::FormatStyle::QualifierOrder

The order in which the qualifiers appear.

Order is an array that can contain any of the following:

  • const
  • inline
  • static
  • friend
  • constexpr
  • volatile
  • restrict
  • type

Note: it MUST contain 'type'. Items to the left of 'type' will be placed to the left of the type and aligned in the order supplied. Items to the right of 'type' will be placed to the right of the type and aligned in the order supplied.

QualifierOrder: ['inline', 'static', 'type', 'const', 'volatile' ]
Version
14

Definition at line 3207 of file Format.h.

Referenced by llvm::yaml::MappingTraits< FormatStyle >::mapping(), operator==(), clang::format::QualifierAlignmentFixer::QualifierAlignmentFixer(), and clang::format::validateQualifierOrder().

◆ RawStringFormats

std::vector<RawStringFormat> clang::format::FormatStyle::RawStringFormats

Defines hints for detecting supported languages code blocks in raw strings.

A raw string with a matching delimiter or a matching enclosing function name will be reformatted assuming the specified language based on the style for that language defined in the .clang-format file. If no style has been defined in the .clang-format file for the specific language, a predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not found, the formatting is based on llvm style. A matching delimiter takes precedence over a matching enclosing function name for determining the language of the raw string contents.

If a canonical delimiter is specified, occurrences of other delimiters for the same language will be updated to the canonical if possible.

There should be at most one specification per language and each delimiter and enclosing function should not occur in multiple specifications.

To configure this in the .clang-format file, use:

RawStringFormats:
- Language: TextProto
Delimiters:
- 'pb'
- 'proto'
EnclosingFunctions:
- 'PARSE_TEXT_PROTO'
BasedOnStyle: google
- Language: Cpp
Delimiters:
- 'cc'
- 'cpp'
BasedOnStyle: llvm
CanonicalDelimiter: 'cc'
Version
6

Definition at line 3267 of file Format.h.

Referenced by clang::format::getCanonicalRawStringDelimiter(), clang::format::getGoogleStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), operator==(), and clang::format::RawStringFormatStyleManager::RawStringFormatStyleManager().

◆ ReferenceAlignment

ReferenceAlignmentStyle clang::format::FormatStyle::ReferenceAlignment

Reference alignment style (overrides PointerAlignment for references).

Version
13

Definition at line 3293 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ ReflowComments

bool clang::format::FormatStyle::ReflowComments

If true, clang-format will attempt to re-flow comments.

That is it will touch a comment and reflow long comments into new lines, trying to obey the ColumnLimit.

false:
// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
/* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
true:
// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
// information
/* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
* information */
Version
3.8

Definition at line 3311 of file Format.h.

Referenced by clang::format::getLLVMStyle(), and llvm::yaml::MappingTraits< FormatStyle >::mapping().

◆ RemoveBracesLLVM

bool clang::format::FormatStyle::RemoveBracesLLVM

Remove optional braces of control statements (if, else, for, and while) in C++ according to the LLVM coding style.

Warning
This option will be renamed and expanded to support other styles. \endwarning
Setting this option to true could lead to incorrect code formatting due to clang-format's lack of complete semantic information. As such, extra care should be taken to review code changes made by this option. \endwarning
false: true:
if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
handleFunctionDecl(D); handleFunctionDecl(D);
} else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D))
handleVarDecl(D); handleVarDecl(D);
}
if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) {
for (auto *A : D.attrs()) { for (auto *A : D.attrs())
if (shouldProcessAttr(A)) { if (shouldProcessAttr(A))
handleAttr(A); handleAttr(A);
} }
}
}
if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
for (auto *A : D.attrs()) { for (auto *A : D.attrs())
handleAttr(A); handleAttr(A);
}
}
if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) {
if (shouldProcess(D)) { if (shouldProcess(D))
handleVarDecl(D); handleVarDecl(D);
} else { else
markAsIgnored(D); markAsIgnored(D);
} }
}
if (a) { vs. if (a)
b(); b();
} else { else if (c)
if (c) { d();
d(); else
} else { e();
e();
}
}
Version
14

Definition at line 3366 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), operator==(), and clang::format::internal::reformat().

◆ RemoveSemicolon

bool clang::format::FormatStyle::RemoveSemicolon

Remove semicolons after the closing brace of a non-empty function.

Warning
Setting this option to true could lead to incorrect code formatting due to clang-format's lack of complete semantic information. As such, extra care should be taken to review code changes made by this option. \endwarning
false: true:
int max(int a, int b) { int max(int a, int b) {
return a > b ? a : b; return a > b ? a : b;
}; }
__DEVICE__ int max(int __a, int __b)
Version
16

Definition at line 3383 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), operator==(), and clang::format::internal::reformat().

◆ RequiresClausePosition

RequiresClausePositionStyle clang::format::FormatStyle::RequiresClausePosition

◆ RequiresExpressionIndentation

RequiresExpressionIndentationKind clang::format::FormatStyle::RequiresExpressionIndentation

The indentation used for requires expression bodies.

Version
16

Definition at line 3490 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SeparateDefinitionBlocks

SeparateDefinitionStyle clang::format::FormatStyle::SeparateDefinitionBlocks

Specifies the use of empty lines to separate definition blocks, including classes, structs, enums, and functions.

Never v.s. Always
#include <cstring> #include <cstring>
struct Foo {
int a, b, c; struct Foo {
}; int a, b, c;
namespace Ns { };
class Bar {
public: namespace Ns {
struct Foobar { class Bar {
int a; public:
int b; struct Foobar {
}; int a;
private: int b;
int t; };
int method1() {
// ... private:
} int t;
enum List {
ITEM1, int method1() {
ITEM2 // ...
}; }
template<typename T>
int method2(T x) { enum List {
// ... ITEM1,
} ITEM2
int i, j, k; };
int method3(int par) {
// ... template<typename T>
} int method2(T x) {
}; // ...
class C {}; }
}
int i, j, k;
int method3(int par) {
// ...
}
};
class C {};
}
Version
14

Definition at line 3548 of file Format.h.

Referenced by clang::format::DefinitionBlockSeparator::analyze(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), operator==(), and clang::format::internal::reformat().

◆ ShortNamespaceLines

unsigned clang::format::FormatStyle::ShortNamespaceLines

The maximal number of unwrapped lines that a short namespace spans.

Defaults to 1.

This determines the maximum length of short namespaces by counting unwrapped lines (i.e. containing neither opening nor closing namespace brace) and makes "FixNamespaceComments" omit adding end comments for those.

namespace a { namespace a {
int foo; int foo;
} } // namespace a
namespace b { namespace b {
int foo; int foo;
int bar; int bar;
} // namespace b } // namespace b
unsigned ShortNamespaceLines
The maximal number of unwrapped lines that a short namespace spans.
Definition: Format.h:3570
Version
13

Definition at line 3570 of file Format.h.

Referenced by clang::format::NamespaceEndCommentsFixer::analyze(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SortIncludes

SortIncludesOptions clang::format::FormatStyle::SortIncludes

◆ SortJavaStaticImport

SortJavaStaticImportOptions clang::format::FormatStyle::SortJavaStaticImport

When sorting Java imports, by default static imports are placed before non-static imports.

If JavaStaticImportAfterImport is After, static imports are placed after non-static imports.

Version
12

Definition at line 3629 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), operator==(), and clang::format::sortJavaImports().

◆ SortUsingDeclarations

SortUsingDeclarationsOptions clang::format::FormatStyle::SortUsingDeclarations

◆ SpaceAfterCStyleCast

bool clang::format::FormatStyle::SpaceAfterCStyleCast

If true, a space is inserted after C style casts.

true: false:
(int) i; vs. (int)i;
__device__ int
Version
3.5

Definition at line 3681 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpaceAfterLogicalNot

bool clang::format::FormatStyle::SpaceAfterLogicalNot

If true, a space is inserted after the logical not operator (!).

true: false:
! someExpression(); vs. !someExpression();
Version
9

Definition at line 3689 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpaceAfterTemplateKeyword

bool clang::format::FormatStyle::SpaceAfterTemplateKeyword

If true, a space will be inserted after the 'template' keyword.

true: false:
template <int> void foo(); vs. template<int> void foo();
Version
4

Definition at line 3697 of file Format.h.

Referenced by clang::format::getLLVMStyle(), clang::format::getMozillaStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpaceAroundPointerQualifiers

SpaceAroundPointerQualifiersStyle clang::format::FormatStyle::SpaceAroundPointerQualifiers

Defines in which cases to put a space before or after pointer qualifiers.

Version
12

Definition at line 3730 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpaceBeforeAssignmentOperators

bool clang::format::FormatStyle::SpaceBeforeAssignmentOperators

If false, spaces will be removed before assignment operators.

true: false:
int a = 5; vs. int a= 5;
a += 42; a+= 42;
Version
3.7

Definition at line 3739 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpaceBeforeCaseColon

bool clang::format::FormatStyle::SpaceBeforeCaseColon

If false, spaces will be removed before case colon.

true: false
switch (x) { vs. switch (x) {
case 1 : break; case 1: break;
} }
Version
12

Definition at line 3749 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpaceBeforeCpp11BracedList

bool clang::format::FormatStyle::SpaceBeforeCpp11BracedList

If true, a space will be inserted before a C++11 braced list used to initialize an object (after the preceding identifier or type).

true: false:
Foo foo { bar }; vs. Foo foo{ bar };
Foo {}; Foo{};
vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
Version
7

Definition at line 3761 of file Format.h.

Referenced by clang::format::getLLVMStyle(), clang::format::getWebKitStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpaceBeforeCtorInitializerColon

bool clang::format::FormatStyle::SpaceBeforeCtorInitializerColon

If false, spaces will be removed before constructor initializer colon.

true: false:
Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
Version
7

Definition at line 3770 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpaceBeforeInheritanceColon

bool clang::format::FormatStyle::SpaceBeforeInheritanceColon

If false, spaces will be removed before inheritance colon.

true: false:
class Foo : Bar {} vs. class Foo: Bar {}
Version
7

Definition at line 3778 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpaceBeforeJsonColon

bool clang::format::FormatStyle::SpaceBeforeJsonColon

If true, a space will be added before a JSON colon.

For other languages, e.g. JavaScript, use SpacesInContainerLiterals instead.

true: false:
{ {
"key" : "value" vs. "key": "value"
} }
Version
17

Definition at line 3789 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpaceBeforeParens

SpaceBeforeParensStyle clang::format::FormatStyle::SpaceBeforeParens

Defines in which cases to put a space before opening parentheses.

Version
3.5

Definition at line 3855 of file Format.h.

Referenced by clang::format::expandPresetsSpaceBeforeParens(), clang::format::getGNUStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpaceBeforeParensOptions

SpaceBeforeParensCustom clang::format::FormatStyle::SpaceBeforeParensOptions

Control of individual space before parentheses.

If SpaceBeforeParens is set to Custom, use this to specify how each individual space before parentheses case should be handled. Otherwise, this is ignored.

# Example of usage:
SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterFunctionDefinitionName: true
Version
14

Definition at line 3971 of file Format.h.

Referenced by clang::format::expandPresetsSpaceBeforeParens(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpaceBeforeRangeBasedForLoopColon

bool clang::format::FormatStyle::SpaceBeforeRangeBasedForLoopColon

If false, spaces will be removed before range-based for loop colon.

true: false:
for (auto v : values) {} vs. for(auto v: values) {}
Version
7

Definition at line 3990 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpaceBeforeSquareBrackets

bool clang::format::FormatStyle::SpaceBeforeSquareBrackets

If true, spaces will be before [.

Lambdas will not be affected. Only the first [ will get a space added.

true: false:
int a [5]; vs. int a[5];
int a [5][5]; vs. int a[5][5];
Version
10

Definition at line 3981 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpaceInEmptyBlock

bool clang::format::FormatStyle::SpaceInEmptyBlock

If true, spaces will be inserted into {}.

true: false:
void f() { } vs. void f() {}
while (true) { } while (true) {}
Version
10

Definition at line 3999 of file Format.h.

Referenced by clang::format::getLLVMStyle(), clang::format::getWebKitStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpaceInEmptyParentheses

bool clang::format::FormatStyle::SpaceInEmptyParentheses

If true, spaces may be inserted into ().

true: false:
void f( ) { vs. void f() {
int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
if (true) { if (true) {
f( ); f();
} }
} }
Version
3.7

Definition at line 4012 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpacesBeforeTrailingComments

unsigned clang::format::FormatStyle::SpacesBeforeTrailingComments

The number of spaces before trailing line comments (// - comments).

This does not affect trailing block comments (/* - comments) as those commonly have different usage patterns and a number of special cases. In the case of Verilog, it doesn't affect a comment right after the opening parenthesis in the port or parameter list in a module header, because it is probably for the port on the following line instead of the parenthesis it follows.

void f() {
if (true) { // foo1
f(); // bar
} // foo
}
unsigned SpacesBeforeTrailingComments
The number of spaces before trailing line comments (// - comments).
Definition: Format.h:4032
Version
3.7

Definition at line 4032 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpacesInAngles

SpacesInAnglesStyle clang::format::FormatStyle::SpacesInAngles

The SpacesInAnglesStyle to use for template argument lists.

Version
3.4

Definition at line 4055 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpacesInConditionalStatement

bool clang::format::FormatStyle::SpacesInConditionalStatement

If true, spaces will be inserted around if/for/switch/while conditions.

true: false:
if ( a ) { ... } vs. if (a) { ... }
while ( i < 5 ) { ... } while (i < 5) { ... }
Version
10

Definition at line 4065 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpacesInContainerLiterals

bool clang::format::FormatStyle::SpacesInContainerLiterals

If true, spaces are inserted inside container literals (e.g.

ObjC and Javascript array and dict literals). For JSON, use SpaceBeforeJsonColon instead.

true: false:
var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
Version
3.7

Definition at line 4076 of file Format.h.

Referenced by clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpacesInCStyleCastParentheses

bool clang::format::FormatStyle::SpacesInCStyleCastParentheses

If true, spaces may be inserted into C style casts.

true: false:
x = ( int32 )y vs. x = (int32)y
Version
3.7

Definition at line 4084 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpacesInLineCommentPrefix

SpacesInLineComment clang::format::FormatStyle::SpacesInLineCommentPrefix

How many spaces are allowed at the start of a line comment.

To disable the maximum set it to -1, apart from that the maximum takes precedence over the minimum.

Minimum = 1
Maximum = -1
// One space is forced
// but more spaces are possible
Minimum = 0
Maximum = 0
//Forces to start every comment directly after the slashes

Note that in line comment sections the relative indent of the subsequent lines is kept, that means the following:

before: after:
Minimum: 1
//if (b) { // if (b) {
// return true; // return true;
//} // }
Maximum: 0
/// List: ///List:
/// - Foo /// - Foo
/// - Bar /// - Bar

This option has only effect if ReflowComments is set to true.

Version
13

Definition at line 4126 of file Format.h.

Referenced by clang::format::NamespaceEndCommentsFixer::analyze(), clang::format::BreakableLineCommentSection::BreakableLineCommentSection(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpacesInParentheses

bool clang::format::FormatStyle::SpacesInParentheses

If true, spaces will be inserted after ( and before ).

true: false:
t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
Version
3.7

Definition at line 4134 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ SpacesInSquareBrackets

bool clang::format::FormatStyle::SpacesInSquareBrackets

If true, spaces will be inserted after [ and before ].

Lambdas without arguments or unspecified size array declarations will not be affected.

true: false:
int a[ 5 ]; vs. int a[5];
std::unique_ptr<int[]> foo() {} // Won't be affected
Version
3.7

Definition at line 4145 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ Standard

LanguageStandard clang::format::FormatStyle::Standard

Parse and format C++ constructs compatible with this standard.

c++03: latest:
vector<set<int> > x; vs. vector<set<int>> x;
Version
3.7

Definition at line 4180 of file Format.h.

Referenced by clang::format::getFormattingLangOpts(), clang::format::getGNUStyle(), clang::format::getGoogleStyle(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ StatementAttributeLikeMacros

std::vector<std::string> clang::format::FormatStyle::StatementAttributeLikeMacros

Macros which are ignored in front of a statement, as if they were an attribute.

So that they are not parsed as identifier, for example for Qts emit.

unsigned char data = 'x';
emit signal(data); // This is parsed as variable declaration.
unsigned char data = 'x';
emit signal(data); // Now it's fine again.
static void emit(Program &P, std::vector< char > &Code, const T &Val, bool &Success)
Helper to write bytecode and bail out if 32-bit offsets become invalid.
std::vector< std::string > StatementAttributeLikeMacros
Macros which are ignored in front of a statement, as if they were an attribute.
Definition: Format.h:4197
AlignConsecutiveStyle AlignConsecutiveDeclarations
Style of aligning consecutive declarations.
Definition: Format.h:297
Version
12

Definition at line 4197 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ StatementMacros

std::vector<std::string> clang::format::FormatStyle::StatementMacros

A vector of macros that should be interpreted as complete statements.

Typical macros are expressions, and require a semi-colon to be added; sometimes this is not the case, and this allows to make clang-format aware of such cases.

For example: Q_UNUSED

Version
8

Definition at line 4208 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ TabWidth

unsigned clang::format::FormatStyle::TabWidth

◆ TypenameMacros

std::vector<std::string> clang::format::FormatStyle::TypenameMacros

A vector of macros that should be interpreted as type declarations instead of as function calls.

These are expected to be macros of the form:

STACK_OF(...)

In the .clang-format configuration file, this can be configured like:

TypenameMacros: ['STACK_OF', 'LIST']

For example: OpenSSL STACK_OF, BSD LIST_ENTRY.

Version
9

Definition at line 4229 of file Format.h.

Referenced by llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ UseTab

UseTabStyle clang::format::FormatStyle::UseTab

The way to use tab characters in the resulting file.

Version
3.7

Definition at line 4254 of file Format.h.

Referenced by clang::format::getLLVMStyle(), clang::format::getMicrosoftStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ VerilogBreakBetweenInstancePorts

bool clang::format::FormatStyle::VerilogBreakBetweenInstancePorts

For Verilog, put each port on its own line in module instantiations.

true:
ffnand ff1(.q(),
.qbar(out1),
.clear(in1),
.preset(in2));
false:
ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));
Version
17

Definition at line 4268 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

◆ WhitespaceSensitiveMacros

std::vector<std::string> clang::format::FormatStyle::WhitespaceSensitiveMacros

A vector of macros which are whitespace-sensitive and should not be touched.

These are expected to be macros of the form:

STRINGIZE(...)

In the .clang-format configuration file, this can be configured like:

WhitespaceSensitiveMacros: ['STRINGIZE', 'PP_STRINGIZE']

For example: BOOST_PP_STRINGIZE

Version
11

Definition at line 4285 of file Format.h.

Referenced by clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().


The documentation for this struct was generated from the following files: