clang-format: Fix space of arrays of pointers to templated types.
authorDaniel Jasper <djasper@google.com>
Thu, 26 Feb 2015 11:30:50 +0000 (11:30 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 26 Feb 2015 11:30:50 +0000 (11:30 +0000)
Before:
  vector<int>(*foo_)[6];

After:
  vector<int> (*foo_)[6];

llvm-svn: 230625

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

index e233052..fa086a9 100644 (file)
@@ -1838,7 +1838,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
   if ((Right.is(TT_BinaryOperator) && !Left.is(tok::l_paren)) ||
       Left.isOneOf(TT_BinaryOperator, TT_ConditionalExpr))
     return true;
-  if (Left.is(TT_TemplateCloser) && Right.is(tok::l_paren))
+  if (Left.is(TT_TemplateCloser) && Right.is(tok::l_paren) &&
+      Right.isNot(TT_FunctionTypeLParen))
     return Style.SpaceBeforeParens == FormatStyle::SBPO_Always;
   if (Right.is(TT_TemplateOpener) && Left.is(tok::r_paren) &&
       Left.MatchingParen && Left.MatchingParen->is(TT_OverloadedOperatorLParen))
index 5bf4d3c..cc27969 100644 (file)
@@ -5606,6 +5606,11 @@ TEST_F(FormatTest, FormatsFunctionTypes) {
   verifyFormat("void f() { function(*some_pointer_var)[0] = 10; }");
 }
 
+TEST_F(FormatTest, FormatsPointersToArrayTypes) {
+  verifyFormat("A (*foo_)[6];");
+  verifyFormat("vector<int> (*foo_)[6];");
+}
+
 TEST_F(FormatTest, BreaksLongVariableDeclarations) {
   verifyFormat("LoooooooooooooooooooooooooooooooooooooooongType\n"
                "    LoooooooooooooooooooooooooooooooooooooooongVariable;");