Index: clang/docs/ClangFormatStyleOptions.rst =================================================================== --- clang/docs/ClangFormatStyleOptions.rst +++ clang/docs/ClangFormatStyleOptions.rst @@ -192,20 +192,6 @@ -**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. @@ -230,6 +216,20 @@ 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. @@ -1390,24 +1390,6 @@ For example: BOOST_FOREACH. -**TypenameMacros** (``std::vector``) - 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. @@ -2134,6 +2116,15 @@ 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 ``()``. @@ -2241,6 +2232,24 @@ **TabWidth** (``unsigned``) The number of columns used for tab stops. +**TypenameMacros** (``std::vector``) + 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. Index: clang/include/clang/Format/Format.h =================================================================== --- clang/include/clang/Format/Format.h +++ clang/include/clang/Format/Format.h @@ -1799,6 +1799,14 @@ /// \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: @@ -1995,6 +2003,7 @@ SpaceBeforeParens == R.SpaceBeforeParens && SpaceBeforeRangeBasedForLoopColon == R.SpaceBeforeRangeBasedForLoopColon && + SpaceInEmptyBlock == R.SpaceInEmptyBlock && SpaceInEmptyParentheses == R.SpaceInEmptyParentheses && SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments && SpacesInAngles == R.SpacesInAngles && Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -494,6 +494,7 @@ 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); @@ -734,6 +735,7 @@ LLVMStyle.ReflowComments = true; LLVMStyle.SpacesInParentheses = false; LLVMStyle.SpacesInSquareBrackets = false; + LLVMStyle.SpaceInEmptyBlock = false; LLVMStyle.SpaceInEmptyParentheses = false; LLVMStyle.SpacesInContainerLiterals = true; LLVMStyle.SpacesInCStyleCastParentheses = false; @@ -979,6 +981,7 @@ Style.ObjCSpaceAfterProperty = true; Style.PointerAlignment = FormatStyle::PAS_Left; Style.SpaceBeforeCpp11BracedList = true; + Style.SpaceInEmptyBlock = true; return Style; } Index: clang/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- clang/lib/Format/UnwrappedLineFormatter.cpp +++ clang/lib/Format/UnwrappedLineFormatter.cpp @@ -551,7 +551,7 @@ (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() && Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -3683,6 +3683,11 @@ 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) { @@ -11756,6 +11761,7 @@ 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);