Index: docs/ClangFormatStyleOptions.rst =================================================================== --- docs/ClangFormatStyleOptions.rst +++ docs/ClangFormatStyleOptions.rst @@ -456,6 +456,9 @@ **SpaceAfterCStyleCast** (``bool``) If ``true``, a space may be inserted after C style casts. +**SpaceAfterTemplate** (``bool``) + If ``true``, a space will be inserted after the 'template' keyword. + **SpaceBeforeAssignmentOperators** (``bool``) If ``false``, spaces will be removed before assignment operators. Index: include/clang/Format/Format.h =================================================================== --- include/clang/Format/Format.h +++ include/clang/Format/Format.h @@ -352,6 +352,9 @@ /// \brief If \c true, a space may be inserted after C style casts. bool SpaceAfterCStyleCast; + /// \brief If \c true, a space will be inserted after the 'template' keyword. + bool SpaceAfterTemplate; + /// \brief If \c false, spaces will be removed before assignment operators. bool SpaceBeforeAssignmentOperators; @@ -493,6 +496,7 @@ PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine && PointerAlignment == R.PointerAlignment && SpaceAfterCStyleCast == R.SpaceAfterCStyleCast && + SpaceAfterTemplate == R.SpaceAfterTemplate && SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators && SpaceBeforeParens == R.SpaceBeforeParens && SpaceInEmptyParentheses == R.SpaceInEmptyParentheses && Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -261,6 +261,7 @@ Style.PenaltyReturnTypeOnItsOwnLine); IO.mapOptional("PointerAlignment", Style.PointerAlignment); IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast); + IO.mapOptional("SpaceAfterTemplate", Style.SpaceAfterTemplate); IO.mapOptional("SpaceBeforeAssignmentOperators", Style.SpaceBeforeAssignmentOperators); IO.mapOptional("SpaceBeforeParens", Style.SpaceBeforeParens); @@ -390,6 +391,7 @@ LLVMStyle.SpacesInContainerLiterals = true; LLVMStyle.SpacesInCStyleCastParentheses = false; LLVMStyle.SpaceAfterCStyleCast = false; + LLVMStyle.SpaceAfterTemplate = true; LLVMStyle.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements; LLVMStyle.SpaceBeforeAssignmentOperators = true; LLVMStyle.SpacesInAngles = false; @@ -487,6 +489,7 @@ MozillaStyle.ObjCSpaceBeforeProtocolList = false; MozillaStyle.PenaltyReturnTypeOnItsOwnLine = 200; MozillaStyle.PointerAlignment = FormatStyle::PAS_Left; + MozillaStyle.SpaceAfterTemplate = false; return MozillaStyle; } Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -1767,9 +1767,10 @@ if (Right.isOneOf(tok::semi, tok::comma)) return false; if (Right.is(tok::less) && - (Left.is(tok::kw_template) || - (Line.Type == LT_ObjCDecl && Style.ObjCSpaceBeforeProtocolList))) + Line.Type == LT_ObjCDecl && Style.ObjCSpaceBeforeProtocolList) return true; + if (Right.is(tok::less) && Left.is(tok::kw_template)) + return Style.SpaceAfterTemplate; if (Left.isOneOf(tok::exclaim, tok::tilde)) return false; if (Left.is(tok::at) && Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -9082,6 +9082,7 @@ CHECK_PARSE_BOOL(SpacesInContainerLiterals); CHECK_PARSE_BOOL(SpacesInCStyleCastParentheses); CHECK_PARSE_BOOL(SpaceAfterCStyleCast); + CHECK_PARSE_BOOL(SpaceAfterTemplate); CHECK_PARSE_BOOL(SpaceBeforeAssignmentOperators); } @@ -10115,6 +10116,12 @@ verifyFormat("A>();", Spaces); } +TEST_F(FormatTest, SpaceAfterTemplate) { + FormatStyle Style = getLLVMStyle(); + Style.SpaceAfterTemplate = false; + verifyFormat("template void foo();", Style); +} + TEST_F(FormatTest, TripleAngleBrackets) { verifyFormat("f<<<1, 1>>>();"); verifyFormat("f<<<1, 1, 1, s>>>();");