-**AlignConsecutiveMacros** (``bool``)
- If ``true``, aligns consecutive C/C++ preprocessor macros.
-
- This will align the C/C++ preprocessor macros of consecutive lines. This
- will result in formattings like
-
- .. code-block:: c++
-
- #define SHORT_NAME 42
- #define LONGER_NAME 0x007f
- #define EVEN_LONGER_NAME (2)
- #define foo(x) (x * x)
- #define bar(y, z) (y + z)
-
**AlignConsecutiveAssignments** (``bool``)
If ``true``, aligns consecutive assignments.
float b = 23;
std::string ccc = 23;
+**AlignConsecutiveMacros** (``bool``)
+ If ``true``, aligns consecutive C/C++ preprocessor macros.
+
+ This will align C/C++ preprocessor macros of consecutive lines.
+ Will result in formattings like
+
+ .. code-block:: c++
+
+ #define SHORT_NAME 42
+ #define LONGER_NAME 0x007f
+ #define EVEN_LONGER_NAME (2)
+ #define foo(x) (x * x)
+ #define bar(y, z) (y + z)
+
**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``)
Options for aligning backslashes in escaped newlines.
For example: BOOST_FOREACH.
-**TypenameMacros** (``std::vector<std::string>``)
- 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:
-
- .. code-block: c++
-
- STACK_OF(...)
-
- In the .clang-format configuration file, this can be configured like:
-
- .. code-block: yaml
-
- TypenameMacros: ['STACK_OF', 'LIST']
-
- For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
-
**IncludeBlocks** (``IncludeBlocksStyle``)
Dependent on the value, multiple ``#include`` blocks can be sorted
as one and divided based on category.
true: false:
for (auto v : values) {} vs. for(auto v: values) {}
+**SpaceInEmptyBlock** (``bool``)
+ If ``true``, spaces will be inserted into ``{}``.
+
+ .. code-block:: c++
+
+ true: false:
+ void f() { } vs. void f() {}
+ while (true) { } while (true) {}
+
**SpaceInEmptyParentheses** (``bool``)
If ``true``, spaces may be inserted into ``()``.
**TabWidth** (``unsigned``)
The number of columns used for tab stops.
+**TypenameMacros** (``std::vector<std::string>``)
+ 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:
+
+ .. code-block:: c++
+
+ STACK_OF(...)
+
+ In the .clang-format configuration file, this can be configured like:
+
+ .. code-block:: yaml
+
+ TypenameMacros: ['STACK_OF', 'LIST']
+
+ For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
+
**UseTab** (``UseTabStyle``)
The way to use tab characters in the resulting file.
/// \endcode
bool SpaceBeforeRangeBasedForLoopColon;
+ /// If ``true``, spaces will be inserted into ``{}``.
+ /// \code
+ /// true: false:
+ /// void f() { } vs. void f() {}
+ /// while (true) { } while (true) {}
+ /// \endcode
+ bool SpaceInEmptyBlock;
+
/// If ``true``, spaces may be inserted into ``()``.
/// \code
/// true: false:
SpaceBeforeParens == R.SpaceBeforeParens &&
SpaceBeforeRangeBasedForLoopColon ==
R.SpaceBeforeRangeBasedForLoopColon &&
+ SpaceInEmptyBlock == R.SpaceInEmptyBlock &&
SpaceInEmptyParentheses == R.SpaceInEmptyParentheses &&
SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
SpacesInAngles == R.SpacesInAngles &&
IO.mapOptional("SpaceBeforeParens", Style.SpaceBeforeParens);
IO.mapOptional("SpaceBeforeRangeBasedForLoopColon",
Style.SpaceBeforeRangeBasedForLoopColon);
+ IO.mapOptional("SpaceInEmptyBlock", Style.SpaceInEmptyBlock);
IO.mapOptional("SpaceInEmptyParentheses", Style.SpaceInEmptyParentheses);
IO.mapOptional("SpacesBeforeTrailingComments",
Style.SpacesBeforeTrailingComments);
LLVMStyle.ReflowComments = true;
LLVMStyle.SpacesInParentheses = false;
LLVMStyle.SpacesInSquareBrackets = false;
+ LLVMStyle.SpaceInEmptyBlock = false;
LLVMStyle.SpaceInEmptyParentheses = false;
LLVMStyle.SpacesInContainerLiterals = true;
LLVMStyle.SpacesInCStyleCastParentheses = false;
Style.ObjCSpaceAfterProperty = true;
Style.PointerAlignment = FormatStyle::PAS_Left;
Style.SpaceBeforeCpp11BracedList = true;
+ Style.SpaceInEmptyBlock = true;
return Style;
}
(Tok->getNextNonComment() == nullptr ||
Tok->getNextNonComment()->is(tok::semi))) {
// We merge empty blocks even if the line exceeds the column limit.
- Tok->SpacesRequiredBefore = 0;
+ Tok->SpacesRequiredBefore = Style.SpaceInEmptyBlock ? 1 : 0;
Tok->CanBreakBefore = true;
return 1;
} else if (Limit != 0 && !Line.startsWithNamespace() &&
EXPECT_EQ("{}", format("{}"));
verifyFormat("enum E {};");
verifyFormat("enum E {}");
+ EXPECT_EQ("void f() { }", format("void f() {}", getWebKitStyle()));
+ FormatStyle Style = getLLVMStyle();
+ Style.AllowShortBlocksOnASingleLine = true;
+ Style.SpaceInEmptyBlock = true;
+ EXPECT_EQ("while (true) { }", format("while (true) {}", Style));
}
TEST_F(FormatTest, FormatBeginBlockEndMacros) {
CHECK_PARSE_BOOL(SpacesInParentheses);
CHECK_PARSE_BOOL(SpacesInSquareBrackets);
CHECK_PARSE_BOOL(SpacesInAngles);
+ CHECK_PARSE_BOOL(SpaceInEmptyBlock);
CHECK_PARSE_BOOL(SpaceInEmptyParentheses);
CHECK_PARSE_BOOL(SpacesInContainerLiterals);
CHECK_PARSE_BOOL(SpacesInCStyleCastParentheses);