clang  8.0.0svn
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"

Collaboration diagram for clang::format::FormatStyle:
Collaboration graph
[legend]

Classes

struct  BraceWrappingFlags
 Precise control over the wrapping of braces. More...
 
struct  FormatStyleSet
 
struct  RawStringFormat
 See documentation of RawStringFormats. More...
 

Public Types

enum  BracketAlignmentStyle { BAS_Align, BAS_DontAlign, BAS_AlwaysBreak }
 Different styles for aligning after open brackets. More...
 
enum  EscapedNewlineAlignmentStyle { ENAS_DontAlign, ENAS_Left, ENAS_Right }
 Different styles for aligning escaped newlines. More...
 
enum  ShortFunctionStyle {
  SFS_None, SFS_InlineOnly, SFS_Empty, SFS_Inline,
  SFS_All
}
 Different styles for merging short functions containing at most one statement. More...
 
enum  DefinitionReturnTypeBreakingStyle { DRTBS_None, DRTBS_All, DRTBS_TopLevel }
 Different ways to break after the function definition return type. More...
 
enum  ReturnTypeBreakingStyle {
  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 { BTDS_No, BTDS_MultiLine, BTDS_Yes }
 Different ways to break after the template declaration. More...
 
enum  BinPackStyle { 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 { BOS_None, BOS_NonAssignment, BOS_All }
 The style of breaking before or after binary operators. More...
 
enum  BraceBreakingStyle {
  BS_Attach, BS_Linux, BS_Mozilla, BS_Stroustrup,
  BS_Allman, BS_GNU, BS_WebKit, BS_Custom
}
 Different ways to attach braces to their surrounding context. More...
 
enum  BreakConstructorInitializersStyle { BCIS_BeforeColon, BCIS_BeforeComma, BCIS_AfterColon }
 Different ways to break initializers. More...
 
enum  BreakInheritanceListStyle { BILS_BeforeColon, BILS_BeforeComma, BILS_AfterColon }
 Different ways to break inheritance list. More...
 
enum  PPDirectiveIndentStyle { PPDIS_None, PPDIS_AfterHash }
 Options for indenting preprocessor directives. More...
 
enum  JavaScriptQuoteStyle { JSQS_Leave, JSQS_Single, JSQS_Double }
 Quotation styles for JavaScript strings. More...
 
enum  LanguageKind {
  LK_None, LK_Cpp, LK_Java, LK_JavaScript,
  LK_ObjC, LK_Proto, LK_TableGen, LK_TextProto
}
 Supported languages. More...
 
enum  NamespaceIndentationKind { NI_None, NI_Inner, NI_All }
 Different ways to indent namespace contents. More...
 
enum  PointerAlignmentStyle { PAS_Left, PAS_Right, PAS_Middle }
 The & and * alignment style. More...
 
enum  SpaceBeforeParensOptions { SBPO_Never, SBPO_ControlStatements, SBPO_Always }
 Different ways to put a space before opening parentheses. More...
 
enum  LanguageStandard { LS_Cpp03, LS_Cpp11, LS_Auto }
 Supported language standards. More...
 
enum  UseTabStyle { UT_Never, UT_ForIndentation, UT_ForContinuationAndIndentation, UT_Always }
 Different ways to use tab in formatting. More...
 

Public Member Functions

bool isCpp () const
 
bool operator== (const FormatStyle &R) const
 
llvm::Optional< FormatStyleGetLanguageStyle (LanguageKind Language) const
 

Static Public Member Functions

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

Public Attributes

int AccessModifierOffset
 The extra indent or outdent of access modifiers, e.g. public:. More...
 
BracketAlignmentStyle AlignAfterOpenBracket
 If true, horizontally aligns arguments after an open bracket. More...
 
bool AlignConsecutiveAssignments
 If true, aligns consecutive assignments. More...
 
bool AlignConsecutiveDeclarations
 If true, aligns consecutive declarations. More...
 
EscapedNewlineAlignmentStyle AlignEscapedNewlines
 Options for aligning backslashes in escaped newlines. More...
 
bool AlignOperands
 If true, horizontally align operands of binary and ternary expressions. More...
 
bool AlignTrailingComments
 If true, aligns trailing comments. More...
 
bool AllowAllParametersOfDeclarationOnNextLine
 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. More...
 
bool AllowShortBlocksOnASingleLine
 Allows contracting simple braced statements to a single line. More...
 
bool AllowShortCaseLabelsOnASingleLine
 If true, short case labels will be contracted to a single line. More...
 
ShortFunctionStyle AllowShortFunctionsOnASingleLine
 Dependent on the value, int f() { return 0; } can be put on a single line. More...
 
bool AllowShortIfStatementsOnASingleLine
 If true, if (a) return; can be put on a single line. More...
 
bool AllowShortLoopsOnASingleLine
 If true, while (true) continue; can be put on a single line. More...
 
DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType
 The function definition return type breaking style to use. More...
 
ReturnTypeBreakingStyle AlwaysBreakAfterReturnType
 The function declaration return type breaking style to use. More...
 
bool AlwaysBreakBeforeMultilineStrings
 If true, always break before multiline string literals. More...
 
BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations
 The template declaration breaking style to use. More...
 
bool BinPackArguments
 If false, a function call's arguments will either be all on the same line or will have one line each. More...
 
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. More...
 
BinaryOperatorStyle BreakBeforeBinaryOperators
 The way to wrap binary operators. More...
 
BraceBreakingStyle BreakBeforeBraces
 The brace breaking style to use. More...
 
BraceWrappingFlags BraceWrapping
 Control of individual brace wrapping cases. More...
 
bool BreakBeforeTernaryOperators
 If true, ternary operators will be placed after line breaks. More...
 
BreakConstructorInitializersStyle BreakConstructorInitializers
 The constructor initializers style to use. More...
 
bool BreakAfterJavaFieldAnnotations
 Break after each annotation on a field in Java files. More...
 
bool BreakStringLiterals
 Allow breaking string literals when formatting. More...
 
unsigned ColumnLimit
 The column limit. More...
 
std::string CommentPragmas
 A regular expression that describes comments with special meaning, which should not be split into lines or otherwise changed. More...
 
BreakInheritanceListStyle BreakInheritanceList
 The inheritance list style to use. More...
 
bool CompactNamespaces
 If true, consecutive namespace declarations will be on the same line. More...
 
bool ConstructorInitializerAllOnOneLineOrOnePerLine
 If the constructor initializers don't fit on a line, put each initializer on its own line. More...
 
unsigned ConstructorInitializerIndentWidth
 The number of characters to use for indentation of constructor initializer lists as well as inheritance lists. More...
 
unsigned ContinuationIndentWidth
 Indent width for line continuations. More...
 
bool Cpp11BracedListStyle
 If true, format braced lists as best suited for C++11 braced lists. More...
 
bool DerivePointerAlignment
 If true, analyze the formatted file for the most common alignment of & and *. More...
 
bool DisableFormat
 Disables formatting completely. More...
 
bool ExperimentalAutoDetectBinPacking
 If true, clang-format detects whether function calls and definitions are formatted with one parameter per line. More...
 
bool FixNamespaceComments
 If true, clang-format adds missing namespace end comments and fixes invalid existing ones. More...
 
std::vector< std::string > ForEachMacros
 A vector of macros that should be interpreted as foreach loops instead of as function calls. More...
 
tooling::IncludeStyle IncludeStyle
 
bool IndentCaseLabels
 Indent case labels one level from the switch statement. More...
 
PPDirectiveIndentStyle IndentPPDirectives
 The preprocessor directive indenting style to use. More...
 
unsigned IndentWidth
 The number of columns to use for indentation. More...
 
bool IndentWrappedFunctionNames
 Indent if a function definition or declaration is wrapped after the type. More...
 
JavaScriptQuoteStyle JavaScriptQuotes
 The JavaScriptQuoteStyle to use for JavaScript strings. More...
 
bool JavaScriptWrapImports
 Whether to wrap JavaScript import/export statements. More...
 
bool KeepEmptyLinesAtTheStartOfBlocks
 If true, the empty line at the start of blocks is kept. More...
 
LanguageKind Language
 Language, this format style is targeted at. More...
 
std::string MacroBlockBegin
 A regular expression matching macros that start a block. More...
 
std::string MacroBlockEnd
 A regular expression matching macros that end a block. More...
 
unsigned MaxEmptyLinesToKeep
 The maximum number of consecutive empty lines to keep. More...
 
NamespaceIndentationKind NamespaceIndentation
 The indentation used for namespaces. More...
 
BinPackStyle ObjCBinPackProtocolList
 Controls bin-packing Objective-C protocol conformance list items into as few lines as possible when they go over ColumnLimit. More...
 
unsigned ObjCBlockIndentWidth
 The number of characters to use for indentation of ObjC blocks. More...
 
bool ObjCSpaceAfterProperty
 
bool ObjCSpaceBeforeProtocolList
 Add a space in front of an Objective-C protocol list, i.e. More...
 
unsigned PenaltyBreakAssignment
 The penalty for breaking around an assignment operator. More...
 
unsigned PenaltyBreakBeforeFirstCallParameter
 The penalty for breaking a function call after call(. More...
 
unsigned PenaltyBreakComment
 The penalty for each line break introduced inside a comment. More...
 
unsigned PenaltyBreakFirstLessLess
 The penalty for breaking before the first <<. More...
 
unsigned PenaltyBreakString
 The penalty for each line break introduced inside a string literal. More...
 
unsigned PenaltyBreakTemplateDeclaration
 The penalty for breaking after template declaration. More...
 
unsigned PenaltyExcessCharacter
 The penalty for each character outside of the column limit. More...
 
unsigned PenaltyReturnTypeOnItsOwnLine
 Penalty for putting the return type of a function onto its own line. More...
 
PointerAlignmentStyle PointerAlignment
 Pointer and reference alignment style. More...
 
std::vector< RawStringFormatRawStringFormats
 Defines hints for detecting supported languages code blocks in raw strings. More...
 
bool ReflowComments
 If true, clang-format will attempt to re-flow comments. More...
 
bool SortIncludes
 If true, clang-format will sort #includes. More...
 
bool SortUsingDeclarations
 If true, clang-format will sort using declarations. More...
 
bool SpaceAfterCStyleCast
 If true, a space is inserted after C style casts. More...
 
bool SpaceAfterTemplateKeyword
 If true, a space will be inserted after the 'template' keyword. More...
 
bool SpaceBeforeAssignmentOperators
 If false, spaces will be removed before assignment operators. More...
 
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). More...
 
bool SpaceBeforeCtorInitializerColon
 If false, spaces will be removed before constructor initializer colon. More...
 
bool SpaceBeforeInheritanceColon
 If false, spaces will be removed before inheritance colon. More...
 
SpaceBeforeParensOptions SpaceBeforeParens
 Defines in which cases to put a space before opening parentheses. More...
 
bool SpaceBeforeRangeBasedForLoopColon
 If false, spaces will be removed before range-based for loop colon. More...
 
bool SpaceInEmptyParentheses
 If true, spaces may be inserted into (). More...
 
unsigned SpacesBeforeTrailingComments
 The number of spaces before trailing line comments (// - comments). More...
 
bool SpacesInAngles
 If true, spaces will be inserted after < and before > in template argument lists. More...
 
bool SpacesInContainerLiterals
 If true, spaces are inserted inside container literals (e.g. More...
 
bool SpacesInCStyleCastParentheses
 If true, spaces may be inserted into C style casts. More...
 
bool SpacesInParentheses
 If true, spaces will be inserted after ( and before ). More...
 
bool SpacesInSquareBrackets
 If true, spaces will be inserted after [ and before ]. More...
 
LanguageStandard Standard
 Format compatible with this standard, e.g. More...
 
unsigned TabWidth
 The number of columns used for tab stops. More...
 
UseTabStyle UseTab
 The way to use tab characters in the resulting file. More...
 

Friends

std::error_code parseConfiguration (StringRef Text, FormatStyle *Style)
 Parse configuration from YAML-formatted text. More...
 

Detailed Description

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

Definition at line 48 of file Format.h.

Member Enumeration Documentation

◆ 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 437 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 427 of file Format.h.

◆ BraceBreakingStyle

Different ways to attach braces to their surrounding context.

Enumerator
BS_Attach 

Always attach braces to surrounding context.

try {
foo();
} catch () {
}
void foo() { bar(); }
class foo {};
if (foo()) {
} else {
}
enum X : int { A, B };
BS_Linux 

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

try {
foo();
} catch () {
}
void foo() { bar(); }
class foo
{
};
if (foo()) {
} else {
}
enum X : int { A, B };
BS_Mozilla 

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

try {
foo();
} catch () {
}
void foo() { bar(); }
class foo
{
};
if (foo()) {
} else {
}
enum X : int { A, B };
BS_Stroustrup 

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

try {
foo();
} catch () {
}
void foo() { bar(); }
class foo
{
};
if (foo()) {
} else {
}
enum X : int
{
A,
B
};
BS_Allman 

Always break before braces.

try {
foo();
}
catch () {
}
void foo() { bar(); }
class foo {
};
if (foo()) {
}
else {
}
enum X : int { A, B };
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.

try
{
foo();
}
catch ()
{
}
void foo() { bar(); }
class foo
{
};
if (foo())
{
}
else
{
}
enum X : int
{
A,
B
};
BS_WebKit 

Like Attach, but break before functions.

try {
foo();
} catch () {
}
void foo() { bar(); }
class foo {
};
if (foo()) {
} else {
}
enum X : int { A, B };
BS_Custom 

Configure each individual brace in BraceWrapping.

Definition at line 480 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);

Definition at line 53 of file Format.h.

◆ BreakConstructorInitializersStyle

Different ways to break initializers.

Enumerator
BCIS_BeforeColon 

Break constructor initializers before the colon and after the commas.

: initializer1(),
initializer2()
BCIS_BeforeComma 

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

: initializer1()
, initializer2()
BCIS_AfterColon 

Break constructor initializers after the colon and commas.

initializer1(),
initializer2()

Definition at line 840 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
{};

Definition at line 897 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 355 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 252 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 104 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 1125 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_Java 

Should be used for Java.

LK_JavaScript 

Should be used for JavaScript.

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/).

Definition at line 1178 of file Format.h.

◆ LanguageStandard

Supported language standards.

Enumerator
LS_Cpp03 

Use C++03-compatible syntax.

LS_Cpp11 

Use features of C++11, C++14 and C++1z (e.g.

A<A<int>> instead of A<A<int> >).

LS_Auto 

Automatic detection based on the input.

Definition at line 1642 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 1248 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 1360 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

Definition at line 1073 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 264 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 193 of file Format.h.

◆ SpaceBeforeParensOptions

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

Definition at line 1527 of file Format.h.

◆ UseTabStyle

Different ways to use tab in formatting.

Enumerator
UT_Never 

Never use tab.

UT_ForIndentation 

Use tabs only for indentation.

UT_ForContinuationAndIndentation 

Use tabs only for line continuation and indentation.

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 1660 of file Format.h.

Member Function Documentation

◆ BuildStyleSetFromConfiguration()

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

◆ GetLanguageStyle()

llvm::Optional< FormatStyle > clang::format::FormatStyle::GetLanguageStyle ( FormatStyle::LanguageKind  Language) const

◆ isCpp()

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

◆ operator==()

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

Definition at line 1675 of file Format.h.

References AccessModifierOffset, AlignAfterOpenBracket, AlignConsecutiveAssignments, AlignConsecutiveDeclarations, AlignEscapedNewlines, AlignOperands, AlignTrailingComments, AllowAllParametersOfDeclarationOnNextLine, AllowShortBlocksOnASingleLine, AllowShortCaseLabelsOnASingleLine, AllowShortFunctionsOnASingleLine, AllowShortIfStatementsOnASingleLine, AllowShortLoopsOnASingleLine, AlwaysBreakAfterReturnType, AlwaysBreakBeforeMultilineStrings, AlwaysBreakTemplateDeclarations, BinPackArguments, BinPackParameters, BreakAfterJavaFieldAnnotations, BreakBeforeBinaryOperators, BreakBeforeBraces, BreakBeforeTernaryOperators, BreakConstructorInitializers, BreakInheritanceList, BreakStringLiterals, ColumnLimit, CommentPragmas, CompactNamespaces, ConstructorInitializerAllOnOneLineOrOnePerLine, ConstructorInitializerIndentWidth, ContinuationIndentWidth, Cpp11BracedListStyle, DerivePointerAlignment, DisableFormat, ExperimentalAutoDetectBinPacking, FixNamespaceComments, ForEachMacros, clang::tooling::IncludeStyle::IncludeBlocks, clang::tooling::IncludeStyle::IncludeCategories, IncludeStyle, IndentCaseLabels, IndentPPDirectives, IndentWidth, IndentWrappedFunctionNames, JavaScriptQuotes, JavaScriptWrapImports, KeepEmptyLinesAtTheStartOfBlocks, Language, MacroBlockBegin, MacroBlockEnd, MaxEmptyLinesToKeep, NamespaceIndentation, ObjCBinPackProtocolList, ObjCBlockIndentWidth, ObjCSpaceAfterProperty, ObjCSpaceBeforeProtocolList, PenaltyBreakAssignment, PenaltyBreakBeforeFirstCallParameter, PenaltyBreakComment, PenaltyBreakFirstLessLess, PenaltyBreakString, PenaltyBreakTemplateDeclaration, PenaltyExcessCharacter, PenaltyReturnTypeOnItsOwnLine, PointerAlignment, RawStringFormats, SpaceAfterCStyleCast, SpaceAfterTemplateKeyword, SpaceBeforeAssignmentOperators, SpaceBeforeCpp11BracedList, SpaceBeforeCtorInitializerColon, SpaceBeforeInheritanceColon, SpaceBeforeParens, SpaceBeforeRangeBasedForLoopColon, SpaceInEmptyParentheses, SpacesBeforeTrailingComments, SpacesInAngles, SpacesInContainerLiterals, SpacesInCStyleCastParentheses, SpacesInParentheses, SpacesInSquareBrackets, Standard, TabWidth, and UseTab.

Friends And Related Function Documentation

◆ parseConfiguration

std::error_code parseConfiguration ( StringRef  Text,
FormatStyle Style 
)
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.

Definition at line 957 of file Format.cpp.

Member Data Documentation

◆ AccessModifierOffset

int clang::format::FormatStyle::AccessModifierOffset

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

Definition at line 50 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.

Definition at line 79 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().

◆ AlignConsecutiveAssignments

bool clang::format::FormatStyle::AlignConsecutiveAssignments

If true, aligns consecutive assignments.

This will align the assignment operators of consecutive lines. This will result in formattings like

int aaaa = 12;
int b = 23;
int ccc = 23;

Definition at line 90 of file Format.h.

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

◆ AlignConsecutiveDeclarations

bool clang::format::FormatStyle::AlignConsecutiveDeclarations

If true, aligns consecutive declarations.

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

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

Definition at line 101 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.

Definition at line 135 of file Format.h.

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

◆ AlignOperands

bool clang::format::FormatStyle::AlignOperands

If true, 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.:

int aaa = bbbbbbbbbbbbbbb +
ccccccccccccccc;

Definition at line 146 of file Format.h.

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

◆ AlignTrailingComments

bool clang::format::FormatStyle::AlignTrailingComments

If true, aligns trailing comments.

true: false:
int a; // My comment a vs. int a; // My comment a
int b = 2; // comment b int b = 2; // comment about b

Definition at line 154 of file Format.h.

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

◆ AllowAllParametersOfDeclarationOnNextLine

bool clang::format::FormatStyle::AllowAllParametersOfDeclarationOnNextLine

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);

Definition at line 171 of file Format.h.

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

◆ AllowShortBlocksOnASingleLine

bool clang::format::FormatStyle::AllowShortBlocksOnASingleLine

Allows contracting simple braced statements to a single line.

E.g., this allows if (a) { return; } to be put on a single line.

Definition at line 176 of file Format.h.

Referenced by clang::format::getLLVMStyle(), 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;
}

Definition at line 189 of file Format.h.

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

◆ AllowShortFunctionsOnASingleLine

ShortFunctionStyle clang::format::FormatStyle::AllowShortFunctionsOnASingleLine

Dependent on the value, int f() { return 0; } can be put on a single line.

Definition at line 241 of file Format.h.

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

◆ AllowShortIfStatementsOnASingleLine

bool clang::format::FormatStyle::AllowShortIfStatementsOnASingleLine

If true, if (a) return; can be put on a single line.

Definition at line 244 of file Format.h.

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

◆ AllowShortLoopsOnASingleLine

bool clang::format::FormatStyle::AllowShortLoopsOnASingleLine

If true, while (true) continue; can be put on a single line.

Definition at line 248 of file Format.h.

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

◆ 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.

Definition at line 335 of file Format.h.

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

◆ AlwaysBreakAfterReturnType

ReturnTypeBreakingStyle clang::format::FormatStyle::AlwaysBreakAfterReturnType

The function declaration return type breaking style to use.

Definition at line 338 of file Format.h.

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

◆ 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";

Definition at line 352 of file Format.h.

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

◆ AlwaysBreakTemplateDeclarations

BreakTemplateDeclarationsStyle clang::format::FormatStyle::AlwaysBreakTemplateDeclarations

◆ 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);
}

Definition at line 409 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) {}

Definition at line 423 of file Format.h.

Referenced by clang::format::getChromiumStyle(), clang::format::getLLVMStyle(), clang::format::getMozillaStyle(), 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

Definition at line 823 of file Format.h.

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

◆ 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;

Definition at line 875 of file Format.h.

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

◆ BreakBeforeBinaryOperators

BinaryOperatorStyle clang::format::FormatStyle::BreakBeforeBinaryOperators

◆ BreakBeforeBraces

BraceBreakingStyle clang::format::FormatStyle::BreakBeforeBraces

◆ BreakBeforeTernaryOperators

bool clang::format::FormatStyle::BreakBeforeTernaryOperators

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

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

Definition at line 837 of file Format.h.

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

◆ BreakConstructorInitializers

BreakConstructorInitializersStyle clang::format::FormatStyle::BreakConstructorInitializers

◆ BreakInheritanceList

BreakInheritanceListStyle clang::format::FormatStyle::BreakInheritanceList

The inheritance list style to use.

Definition at line 926 of file Format.h.

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

◆ BreakStringLiterals

bool clang::format::FormatStyle::BreakStringLiterals

◆ 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

Definition at line 894 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 {
}}}

Definition at line 949 of file Format.h.

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

◆ ConstructorInitializerAllOnOneLineOrOnePerLine

bool clang::format::FormatStyle::ConstructorInitializerAllOnOneLineOrOnePerLine

If the constructor initializers don't fit on a line, put each initializer on its own line.

true:
SomeClass::Constructor()
: aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
return 0;
}
false:
SomeClass::Constructor()
: aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
return 0;
}

Definition at line 967 of file Format.h.

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

◆ ConstructorInitializerIndentWidth

unsigned clang::format::FormatStyle::ConstructorInitializerIndentWidth

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

Definition at line 971 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);

Definition at line 981 of file Format.h.

Referenced by clang::format::getChromiumStyle(), clang::format::BreakableBlockComment::getContentIndent(), clang::format::getLLVMStyle(), clang::format::getMozillaStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), 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 };

Definition at line 1003 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(), clang::format::FormatToken::opensBlockOrBlockTypeList(), operator==(), and clang::format::CommaSeparatedList::precomputeFormattingInfos().

◆ DerivePointerAlignment

bool clang::format::FormatStyle::DerivePointerAlignment

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.

Definition at line 1010 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

Disables formatting completely.

Definition at line 1013 of file Format.h.

Referenced by clang::format::getLLVMStyle(), clang::format::getNoStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), 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.

Definition at line 1025 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 and fixes invalid existing ones.

true: false:
namespace a { vs. namespace a {
foo(); foo();
} // namespace a; }

Definition at line 1035 of file Format.h.

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

◆ 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.

Definition at line 1052 of file Format.h.

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

◆ IncludeStyle

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

◆ 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.

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

Definition at line 1070 of file Format.h.

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

◆ IndentPPDirectives

PPDirectiveIndentStyle clang::format::FormatStyle::IndentPPDirectives

The preprocessor directive indenting style to use.

Definition at line 1095 of file Format.h.

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

◆ IndentWidth

unsigned clang::format::FormatStyle::IndentWidth

The number of columns to use for indentation.

void f() {
someFunction();
if (true, false) {
f();
}
}

Definition at line 1108 of file Format.h.

Referenced by clang::format::getChromiumStyle(), clang::format::getLLVMStyle(), 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();

Definition at line 1121 of file Format.h.

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

◆ JavaScriptQuotes

JavaScriptQuoteStyle clang::format::FormatStyle::JavaScriptQuotes

The JavaScriptQuoteStyle to use for JavaScript strings.

Definition at line 1147 of file Format.h.

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

◆ 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"

Definition at line 1161 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(); }
}

Definition at line 1171 of file Format.h.

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

◆ Language

LanguageKind clang::format::FormatStyle::Language

◆ 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

Definition at line 1229 of file Format.h.

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

◆ MacroBlockEnd

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

A regular expression matching macros that end a block.

Definition at line 1232 of file Format.h.

Referenced by clang::format::FormatTokenLexer::FormatTokenLexer(), 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;
}

Definition at line 1245 of file Format.h.

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

◆ NamespaceIndentation

NamespaceIndentationKind clang::format::FormatStyle::NamespaceIndentation

◆ 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> {
}

Definition at line 1314 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];
}];

Definition at line 1324 of file Format.h.

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

◆ ObjCSpaceAfterProperty

bool clang::format::FormatStyle::ObjCSpaceAfterProperty

◆ 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>.

Definition at line 1332 of file Format.h.

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

◆ PenaltyBreakAssignment

unsigned clang::format::FormatStyle::PenaltyBreakAssignment

The penalty for breaking around an assignment operator.

Definition at line 1335 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(.

Definition at line 1338 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.

Definition at line 1341 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 <<.

Definition at line 1344 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.

Definition at line 1347 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.

Definition at line 1350 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.

Definition at line 1353 of file Format.h.

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

◆ PenaltyReturnTypeOnItsOwnLine

unsigned clang::format::FormatStyle::PenaltyReturnTypeOnItsOwnLine

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

Definition at line 1357 of file Format.h.

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

◆ PointerAlignment

PointerAlignmentStyle clang::format::FormatStyle::PointerAlignment

◆ 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'

Definition at line 1438 of file Format.h.

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

◆ ReflowComments

bool clang::format::FormatStyle::ReflowComments

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

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

Definition at line 1452 of file Format.h.

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

◆ SortIncludes

bool clang::format::FormatStyle::SortIncludes

If true, clang-format will sort #includes.

false: true:
#include "b.h" vs. #include "a.h"
#include "a.h" #include "b.h"

Definition at line 1460 of file Format.h.

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

◆ SortUsingDeclarations

bool clang::format::FormatStyle::SortUsingDeclarations

If true, clang-format will sort using declarations.

The order of using declarations is 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.

false: true:
using std::cout; vs. using std::cin;
using std::cin; using std::cout;

Definition at line 1476 of file Format.h.

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

◆ SpaceAfterCStyleCast

bool clang::format::FormatStyle::SpaceAfterCStyleCast

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

true: false:
(int) i; vs. (int)i;

Definition at line 1483 of file Format.h.

Referenced by clang::format::getGoogleStyle(), 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();

Definition at line 1490 of file Format.h.

Referenced by clang::format::getLLVMStyle(), clang::format::getMozillaStyle(), 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;

Definition at line 1498 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 };

Definition at line 1509 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) {}

Definition at line 1517 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 {}

Definition at line 1524 of file Format.h.

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

◆ SpaceBeforeParens

SpaceBeforeParensOptions clang::format::FormatStyle::SpaceBeforeParens

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

Definition at line 1562 of file Format.h.

Referenced by clang::format::getGNUStyle(), 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) {}

Definition at line 1570 of file Format.h.

Referenced by clang::format::getLLVMStyle(), 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();
} }
} }

Definition at line 1582 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.

void f() {
if (true) { // foo1
f(); // bar
} // foo
}

Definition at line 1598 of file Format.h.

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

◆ SpacesInAngles

bool clang::format::FormatStyle::SpacesInAngles

If true, spaces will be inserted after < and before > in template argument lists.

true: false:
static_cast< int >(arg); vs. static_cast<int>(arg);
std::function< void(int) > fct; std::function<void(int)> fct;

Definition at line 1607 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).

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

Definition at line 1616 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

Definition at line 1623 of file Format.h.

Referenced by 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;

Definition at line 1630 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 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

Definition at line 1639 of file Format.h.

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

◆ Standard

LanguageStandard clang::format::FormatStyle::Standard

Format compatible with this standard, e.g.

use A<A<int> > instead of A<A<int>> for LS_Cpp03.

Definition at line 1654 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==().

◆ TabWidth

unsigned clang::format::FormatStyle::TabWidth

◆ UseTab

UseTabStyle clang::format::FormatStyle::UseTab

The way to use tab characters in the resulting file.

Definition at line 1673 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: