/// are not also definitions after the type.
bool IndentFunctionDeclarationAfterType;
- /// \brief If \c true, spaces will be inserted after every '(' and before
- /// every ')'.
+ /// \brief If \c true, spaces will be inserted after '(' and before ')'.
bool SpacesInParentheses;
+ /// \brief If \c true, spaces will be inserted after '<' and before '>' in
+ /// template argument lists
+ bool SpacesInAngles;
+
/// \brief If \c false, spaces may be inserted into '()'.
bool SpaceInEmptyParentheses;
Cpp11BracedListStyle == R.Cpp11BracedListStyle &&
Standard == R.Standard && TabWidth == R.TabWidth &&
UseTab == R.UseTab && SpacesInParentheses == R.SpacesInParentheses &&
+ SpacesInAngles == R.SpacesInAngles &&
SpaceInEmptyParentheses == R.SpaceInEmptyParentheses &&
SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses &&
SpaceAfterControlStatementKeyword ==
IO.mapOptional("IndentFunctionDeclarationAfterType",
Style.IndentFunctionDeclarationAfterType);
IO.mapOptional("SpacesInParentheses", Style.SpacesInParentheses);
+ IO.mapOptional("SpacesInAngles", Style.SpacesInAngles);
IO.mapOptional("SpaceInEmptyParentheses", Style.SpaceInEmptyParentheses);
IO.mapOptional("SpacesInCStyleCastParentheses",
Style.SpacesInCStyleCastParentheses);
LLVMStyle.SpaceAfterControlStatementKeyword = true;
LLVMStyle.SpaceBeforeAssignmentOperators = true;
LLVMStyle.ContinuationIndentWidth = 4;
+ LLVMStyle.SpacesInAngles = false;
setDefaultPenalties(LLVMStyle);
LLVMStyle.PenaltyReturnTypeOnItsOwnLine = 60;
GoogleStyle.SpaceAfterControlStatementKeyword = true;
GoogleStyle.SpaceBeforeAssignmentOperators = true;
GoogleStyle.ContinuationIndentWidth = 4;
+ GoogleStyle.SpacesInAngles = false;
setDefaultPenalties(GoogleStyle);
GoogleStyle.PenaltyReturnTypeOnItsOwnLine = 200;
(Left.MatchingParen && Left.MatchingParen->Type == TT_CastRParen))
? Style.SpacesInCStyleCastParentheses
: Style.SpacesInParentheses;
+ if (Style.SpacesInAngles &&
+ ((Left.Type == TT_TemplateOpener) != (Right.Type == TT_TemplateCloser)))
+ return true;
if (Right.isOneOf(tok::semi, tok::comma))
return false;
if (Right.is(tok::less) &&
if (Tok.Previous->is(tok::greater) && Tok.is(tok::greater)) {
return Tok.Type == TT_TemplateCloser &&
Tok.Previous->Type == TT_TemplateCloser &&
- Style.Standard != FormatStyle::LS_Cpp11;
+ (Style.Standard != FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
}
if (Tok.isOneOf(tok::arrowstar, tok::periodstar) ||
Tok.Previous->isOneOf(tok::arrowstar, tok::periodstar))
CHECK_PARSE_BOOL(Cpp11BracedListStyle);
CHECK_PARSE_BOOL(IndentFunctionDeclarationAfterType);
CHECK_PARSE_BOOL(SpacesInParentheses);
+ CHECK_PARSE_BOOL(SpacesInAngles);
CHECK_PARSE_BOOL(SpaceInEmptyParentheses);
CHECK_PARSE_BOOL(SpacesInCStyleCastParentheses);
CHECK_PARSE_BOOL(SpaceAfterControlStatementKeyword);
format("int i = longFunction(arg);", SixIndent));
}
+TEST_F(FormatTest, SpacesInAngles) {
+ FormatStyle Spaces = getLLVMStyle();
+ Spaces.SpacesInAngles = true;
+
+ verifyFormat("static_cast< int >(arg);", Spaces);
+ verifyFormat("template < typename T0, typename T1 > void f() {}", Spaces);
+ verifyFormat("f< int, float >();", Spaces);
+ verifyFormat("template <> g() {}", Spaces);
+ verifyFormat("template < std::vector< int > > f() {}", Spaces);
+
+ Spaces.Standard = FormatStyle::LS_Cpp03;
+ Spaces.SpacesInAngles = true;
+ verifyFormat("A< A< int > >();", Spaces);
+
+ Spaces.SpacesInAngles = false;
+ verifyFormat("A<A<int> >();", Spaces);
+
+ Spaces.Standard = FormatStyle::LS_Cpp11;
+ Spaces.SpacesInAngles = true;
+ verifyFormat("A< A< int > >();", Spaces);
+
+ Spaces.SpacesInAngles = false;
+ verifyFormat("A<A<int>>();", Spaces);
+}
+
} // end namespace tooling
} // end namespace clang