[PATCH] D14927: clang-format: Add SpaceBeforeTemplateParameterList option
Nico Rieck via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 23 07:25:45 PST 2015
nrieck created this revision.
nrieck added a subscriber: cfe-commits.
Herald added a subscriber: klimek.
Adds an option to control whether a space is inserted between "template" and "<". Currently a space is always inserted (as the LLVM style requires), but to me this seems like the less popular option.
Looking at a few files from Mozilla and Chromium they seem to also skip the space. Should this option be disabled for their styles?
http://reviews.llvm.org/D14927
Files:
include/clang/Format/Format.h
lib/Format/Format.cpp
lib/Format/TokenAnnotator.cpp
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;
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: 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 &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14927.40927.patch
Type: text/x-patch
Size: 2800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151123/38e15c4f/attachment.bin>
More information about the cfe-commits
mailing list