From 6ba1638f0b1062da45933dbdf8538f121cbd0e2c Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 28 Jul 2014 13:19:58 +0000 Subject: [PATCH] clang-format: Improve operator and template recognition. Before: static_assert(is_convertible < A &&, B > ::value, "AAA"); After: static_assert(is_convertible::value, "AAA"); llvm-svn: 214075 --- clang/lib/Format/TokenAnnotator.cpp | 10 +++------- clang/unittests/Format/FormatTest.cpp | 3 ++- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 6a7180b..885d147 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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 && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 28bdf32..c942ae9 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -4578,6 +4578,7 @@ TEST_F(FormatTest, UnderstandsTemplateParameters) { verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaa >> aaaaa);", getLLVMStyleWithColumns(60)); + verifyFormat("static_assert(is_convertible::value, \"AAA\");"); } TEST_F(FormatTest, UnderstandsBinaryOperators) { @@ -4883,7 +4884,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { // FIXME: We cannot handle this case yet; we might be able to figure out that // foo d > v; doesn't make sense. - verifyFormat("foo d > v;"); + verifyFormat("foo d> v;"); FormatStyle PointerMiddle = getLLVMStyle(); PointerMiddle.PointerAlignment = FormatStyle::PAS_Middle; -- 2.7.4