diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -919,6 +919,8 @@
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
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6618,7 +6618,10 @@
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;");