From: Owen Pan Date: Fri, 16 Aug 2019 21:49:17 +0000 (+0000) Subject: [clang-format] Fix the bug that joins template closer and > or >> X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b8b260edfffc7fd60dfada944b57fe1efdba389e;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@369157 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index c0533bbcbd..62f7130dc8 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 3fe75ec233..0aeecc0e12 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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;");