aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-03-20 09:53:18 +0000
committerDaniel Jasper <djasper@google.com>2013-03-20 09:53:18 +0000
commit9322aaee900b872c98f8fc10b38a231cb1e9b57a (patch)
treeeea30062006985c3b1546d1f1b52c53d4daf66fc /lib
parent3309229f77222970cce344eaa6908ad9320d2d82 (diff)
Improve formatting of function types in template parameters.
Before: A<int * (int)>; After: A<int *(int)>; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177505 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Format/TokenAnnotator.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 4ac4c9b1b8..51fd4e6654 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -681,10 +681,15 @@ private:
if (PrevToken->FormatTok.Tok.isLiteral() ||
PrevToken->isOneOf(tok::r_paren, tok::r_square) ||
- NextToken->FormatTok.Tok.isLiteral() || isUnaryOperator(*NextToken) ||
- NextToken->isOneOf(tok::l_paren, tok::l_square))
+ NextToken->FormatTok.Tok.isLiteral() || isUnaryOperator(*NextToken))
return TT_BinaryOperator;
+ // "*(" is probably part of a function type if within template parameters.
+ // Otherwise, it is probably a binary operator.
+ if (NextToken->is(tok::l_paren))
+ return Contexts.back().ContextKind == tok::less ? TT_PointerOrReference
+ : TT_BinaryOperator;
+
// It is very unlikely that we are going to find a pointer or reference type
// definition on the RHS of an assignment.
if (IsExpression)
@@ -989,7 +994,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
!Style.PointerBindsToType);
if (Left.Type == TT_PointerOrReference)
return Right.FormatTok.Tok.isLiteral() ||
- ((Right.Type != TT_PointerOrReference) && Style.PointerBindsToType);
+ ((Right.Type != TT_PointerOrReference) &&
+ Right.isNot(tok::l_paren) && Style.PointerBindsToType);
if (Right.is(tok::star) && Left.is(tok::l_paren))
return false;
if (Left.is(tok::l_square))