<div dir="ltr">Friendly ping:)<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 31, 2016 at 10:16 PM, Branko Kokanovic <span dir="ltr"><<a href="mailto:branko@kokanovic.org" target="_blank">branko@kokanovic.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">branko created this revision.<br>
branko added a reviewer: djasper.<br>
branko added a subscriber: cfe-commits.<br>
Herald added a subscriber: klimek.<br>
<br>
Actual regression was introduced in r272668. This revision fixes JS script, but also regress Cpp case. It manifests with spaces added when template is followed with array. Bug 30527 mentions case of array as a nested template type (foo<bar<baz>[]>). Fix is to detect such case and to prevent treating it as array initialization, but as a subscript case. However, before r272668, this case was treated simple because we were detecting it as a StartsObjCMethodExpr. Same was true for other similar case - array of templates (foo<int>[]). This patch tries to address two problems: 1) fixing regression 2) making sure both cases (array as a nested type, array of templates) which were entering StartsObjCMethodExpr branch are handled now appropriately.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D26163" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D26163</a><br>
<br>
Files:<br>
  lib/Format/TokenAnnotator.cpp<br>
  unittests/Format/FormatTest.<wbr>cpp<br>
<br>
<br>
Index: unittests/Format/FormatTest.<wbr>cpp<br>
==============================<wbr>==============================<wbr>=======<br>
--- unittests/Format/FormatTest.<wbr>cpp<br>
+++ unittests/Format/FormatTest.<wbr>cpp<br>
@@ -11501,6 +11501,26 @@<br>
   verifyFormat("include \"<a href="http://a.td" rel="noreferrer" target="_blank">a.td</a>\"\ninclude \"<a href="http://b.td" rel="noreferrer" target="_blank">b.td</a>\"", Style);<br>
 }<br>
<br>
+TEST_F(FormatTest, ArrayOfTemplates) {<br>
+  EXPECT_EQ("auto a = new unique_ptr<int>[10];",<br>
+            format("auto a = new unique_ptr<int > [ 10];"));<br>
+<br>
+  FormatStyle Spaces = getLLVMStyle();<br>
+  Spaces.SpacesInSquareBrackets = true;<br>
+  EXPECT_EQ("auto a = new unique_ptr<int>[ 10 ];",<br>
+            format("auto a = new unique_ptr<int > [10];", Spaces));<br>
+}<br>
+<br>
+TEST_F(FormatTest, ArrayAsTemplateType) {<br>
+  EXPECT_EQ("auto a = unique_ptr<Foo<Bar>[10]>;",<br>
+            format("auto a = unique_ptr < Foo < Bar>[ 10]> ;"));<br>
+<br>
+  FormatStyle Spaces = getLLVMStyle();<br>
+  Spaces.SpacesInSquareBrackets = true;<br>
+  EXPECT_EQ("auto a = unique_ptr<Foo<Bar>[ 10 ]>;",<br>
+            format("auto a = unique_ptr < Foo < Bar>[10]> ;", Spaces));<br>
+}<br>
+<br>
 // Since this test case uses UNIX-style file path. We disable it for MS<br>
 // compiler.<br>
 #if !defined(_MSC_VER) && !defined(__MINGW32__)<br>
Index: lib/Format/TokenAnnotator.cpp<br>
==============================<wbr>==============================<wbr>=======<br>
--- lib/Format/TokenAnnotator.cpp<br>
+++ lib/Format/TokenAnnotator.cpp<br>
@@ -305,7 +305,17 @@<br>
     FormatToken *Left = CurrentToken->Previous;<br>
     Left->ParentBracket = Contexts.back().ContextKind;<br>
     FormatToken *Parent = Left->getPreviousNonComment();<br>
-    bool StartsObjCMethodExpr =<br>
+<br>
+    // Cases where '>' is followed by '['.<br>
+    // In C++, this can happen either in array of templates (foo<int>[10])<br>
+    // or when array is a nested template type (unique_ptr<type1<type2>[]>).<br>
+    bool CppArrayTemplates =<br>
+        Style.Language == FormatStyle::LK_Cpp && Parent &&<br>
+        Parent->is(TT_TemplateCloser) &&<br>
+        (Contexts.back().<wbr>CanBeExpression || Contexts.back().IsExpression ||<br>
+         Contexts.back().<wbr>InTemplateArgument);<br>
+<br>
+    bool StartsObjCMethodExpr = !CppArrayTemplates &&<br>
         Style.Language == FormatStyle::LK_Cpp &&<br>
         Contexts.back().<wbr>CanBeExpression && Left->isNot(TT_LambdaLSquare) &&<br>
         CurrentToken->isNot(tok::l_<wbr>brace) &&<br>
@@ -326,7 +336,7 @@<br>
                  Parent->isOneOf(tok::l_brace, tok::comma)) {<br>
         Left->Type = TT_JsComputedPropertyName;<br>
       } else if (Style.Language == FormatStyle::LK_Proto ||<br>
-                 (Parent &&<br>
+                 (!CppArrayTemplates && Parent &&<br>
                   Parent->isOneOf(TT_<wbr>BinaryOperator, TT_TemplateCloser, tok::at,<br>
                                   tok::comma, tok::l_paren, tok::l_square,<br>
                                   tok::question, tok::colon, tok::kw_return,<br>
<br>
<br>
</blockquote></div><br></div>