[PATCH] D66332: [clang-format] Fix the bug that joins template closer and > or >>

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 15 22:05:01 PDT 2019


owenpan created this revision.
owenpan added reviewers: sammccall, MyDeveloperDay, klimek, djasper.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Also fixes a buggy test case.

See PR42404


Repository:
  rC Clang

https://reviews.llvm.org/D66332

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -6618,7 +6618,10 @@
   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;");
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ 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 ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66332.215538.patch
Type: text/x-patch
Size: 1170 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190816/9222f73e/attachment.bin>


More information about the cfe-commits mailing list