From 7a5b206891d6e18a064740fe4a9739f9d26345ac 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"); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214075 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 10 +++------- unittests/Format/FormatTest.cpp | 3 ++- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 6a7180bfb0..885d147b9b 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 28bdf3293a..c942ae926d 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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.40.0