r214075 - clang-format: Improve operator and template recognition.
Daniel Jasper
djasper at google.com
Mon Jul 28 06:19:58 PDT 2014
Author: djasper
Date: Mon Jul 28 08:19:58 2014
New Revision: 214075
URL: http://llvm.org/viewvc/llvm-project?rev=214075&view=rev
Log:
clang-format: Improve operator and template recognition.
Before:
static_assert(is_convertible < A &&, B > ::value, "AAA");
After:
static_assert(is_convertible<A &&, B>::value, "AAA");
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=214075&r1=214074&r2=214075&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jul 28 08:19:58 2014
@@ -69,12 +69,8 @@ private:
// parameters.
// FIXME: This is getting out of hand, write a decent parser.
if (CurrentToken->Previous->isOneOf(tok::pipepipe, tok::ampamp) &&
- ((CurrentToken->Previous->Type == TT_BinaryOperator &&
- // Toplevel bool expressions do not make lots of sense;
- // If we're on the top level, it contains only the base context and
- // the context for the current opening angle bracket.
- Contexts.size() > 2) ||
- Contexts[Contexts.size() - 2].IsExpression) &&
+ CurrentToken->Previous->Type == TT_BinaryOperator &&
+ Contexts[Contexts.size() - 2].IsExpression &&
Line.First->isNot(tok::kw_template))
return false;
updateParameterCount(Left, CurrentToken);
@@ -924,7 +920,7 @@ private:
if (NextToken->is(tok::l_square) && NextToken->Type != TT_LambdaLSquare)
return TT_PointerOrReference;
- if (NextToken->is(tok::kw_operator))
+ if (NextToken->isOneOf(tok::kw_operator, tok::comma))
return TT_PointerOrReference;
if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen &&
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=214075&r1=214074&r2=214075&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jul 28 08:19:58 2014
@@ -4578,6 +4578,7 @@ TEST_F(FormatTest, UnderstandsTemplatePa
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaa >> aaaaa);",
getLLVMStyleWithColumns(60));
+ verifyFormat("static_assert(is_convertible<A &&, B>::value, \"AAA\");");
}
TEST_F(FormatTest, UnderstandsBinaryOperators) {
@@ -4883,7 +4884,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
// FIXME: We cannot handle this case yet; we might be able to figure out that
// foo<x> d > v; doesn't make sense.
- verifyFormat("foo<a < b && c> d > v;");
+ verifyFormat("foo<a<b && c> d> v;");
FormatStyle PointerMiddle = getLLVMStyle();
PointerMiddle.PointerAlignment = FormatStyle::PAS_Middle;
More information about the cfe-commits
mailing list