From ac67414618df9fdc24754b05cf438f8f7568f04a Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Fri, 16 Aug 2019 21:49:17 +0000 Subject: [PATCH] [clang-format] Fix the bug that joins template closer and > or >> Also fixes a buggy test case. See PR42404 Differential Revision: https://reviews.llvm.org/D66332 llvm-svn: 369157 --- clang/lib/Format/TokenAnnotator.cpp | 2 ++ clang/unittests/Format/FormatTest.cpp | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index c0533bbcbdca..62f7130dc899 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -919,6 +919,8 @@ private: case tok::greater: if (Style.Language != FormatStyle::LK_TextProto) Tok->Type = TT_BinaryOperator; + if (Tok->Previous && Tok->Previous->is(TT_TemplateCloser)) + Tok->SpacesRequiredBefore = 1; break; case tok::kw_operator: if (Style.Language == FormatStyle::LK_TextProto || diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 3fe75ec233c9..0aeecc0e1221 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -6618,7 +6618,10 @@ TEST_F(FormatTest, UnderstandsTemplateParameters) { EXPECT_EQ("auto x = [] { A>> a; };", format("auto x=[]{A >> a;};", getGoogleStyle())); - verifyFormat("A> a;", getChromiumStyle(FormatStyle::LK_Cpp)); + verifyFormat("A> a;", getChromiumStyle(FormatStyle::LK_Cpp)); + + verifyFormat("int i = a<1> >> 1;"); + verifyFormat("bool b = a<1> > 1;"); verifyFormat("test >> a >> b;"); verifyFormat("test << a >> b;");