Index: include/clang/Format/Format.h =================================================================== --- include/clang/Format/Format.h +++ include/clang/Format/Format.h @@ -495,6 +495,10 @@ /// \brief Defines in which cases to put a space before opening parentheses. SpaceBeforeParensOptions SpaceBeforeParens; + /// If \c true, a space is inserted between 'template' and the opening angle + /// bracket of a template parameter list. + bool SpaceBeforeTemplateParameterList; + /// \brief If \c true, spaces may be inserted into '()'. bool SpaceInEmptyParentheses; @@ -622,6 +626,8 @@ SpaceAfterCStyleCast == R.SpaceAfterCStyleCast && SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators && SpaceBeforeParens == R.SpaceBeforeParens && + SpaceBeforeTemplateParameterList == + R.SpaceBeforeTemplateParameterList && SpaceInEmptyParentheses == R.SpaceInEmptyParentheses && SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments && SpacesInAngles == R.SpacesInAngles && Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -290,6 +290,8 @@ IO.mapOptional("SpaceBeforeAssignmentOperators", Style.SpaceBeforeAssignmentOperators); IO.mapOptional("SpaceBeforeParens", Style.SpaceBeforeParens); + IO.mapOptional("SpaceBeforeTemplateParameterList", + Style.SpaceBeforeTemplateParameterList); IO.mapOptional("SpaceInEmptyParentheses", Style.SpaceInEmptyParentheses); IO.mapOptional("SpacesBeforeTrailingComments", Style.SpacesBeforeTrailingComments); @@ -497,6 +499,7 @@ LLVMStyle.SpacesInCStyleCastParentheses = false; LLVMStyle.SpaceAfterCStyleCast = false; LLVMStyle.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements; + LLVMStyle.SpaceBeforeTemplateParameterList = true; LLVMStyle.SpaceBeforeAssignmentOperators = true; LLVMStyle.SpacesInAngles = false; Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -1826,9 +1826,10 @@ : Style.SpacesInParentheses; if (Right.isOneOf(tok::semi, tok::comma)) return false; + if (Right.is(tok::less) && Left.is(tok::kw_template)) + return Style.SpaceBeforeTemplateParameterList; 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 (Left.isOneOf(tok::exclaim, tok::tilde)) return false;