]> granicus.if.org Git - clang/commitdiff
[clang-format] Fix the bug that joins template closer and > or >>
authorOwen Pan <owenpiano@gmail.com>
Fri, 16 Aug 2019 21:49:17 +0000 (21:49 +0000)
committerOwen Pan <owenpiano@gmail.com>
Fri, 16 Aug 2019 21:49:17 +0000 (21:49 +0000)
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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index c0533bbcbdca312395fe6a94cb8e6166614b0542..62f7130dc899dbc8878e8b0c6fb91af22588d5f1 100644 (file)
@@ -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 ||
index 3fe75ec233c9ede9f907cc49369fa0e088ab0670..0aeecc0e1221484fe381128cd2c596e5a8699df5 100644 (file)
@@ -6618,7 +6618,10 @@ TEST_F(FormatTest, UnderstandsTemplateParameters) {
   EXPECT_EQ("auto x = [] { A<A<A<A>>> a; };",
             format("auto x=[]{A<A<A<A> >> a;};", getGoogleStyle()));
 
-  verifyFormat("A<A>> a;", getChromiumStyle(FormatStyle::LK_Cpp));
+  verifyFormat("A<A<int>> 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;");