]> granicus.if.org Git - clang/commitdiff
Don't allow line breaks after template parameters.
authorDaniel Jasper <djasper@google.com>
Wed, 2 Jan 2013 18:30:06 +0000 (18:30 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 2 Jan 2013 18:30:06 +0000 (18:30 +0000)
This fixes llvm.org/PR14786.

We will need to split there as a last resort, but that should be done
consistently independent of whether the type is a template type or not.

Before:
template <typename T>
aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<T>
                    ::aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
template <typename T>
aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaa,
                    aaaaaaaaaaaaaaaaaaaaaaaaaa<T>::aaaaaaaaaa,
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171400 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 3c337ec06314cb9c50beea53e99ad0450e834540..6fb75a657a3d4b53116db6bccee68e559e60017d 100644 (file)
@@ -941,7 +941,10 @@ private:
   }
 
   bool canBreakBefore(unsigned i) {
+    if (Annotations[i - 1].ClosesTemplateDeclaration)
+      return true;
     if (Annotations[i - 1].Type == TokenAnnotation::TT_PointerOrReference ||
+        Annotations[i - 1].Type == TokenAnnotation::TT_TemplateCloser ||
         Annotations[i].Type == TokenAnnotation::TT_ConditionalExpr) {
       return false;
     }
index 574d685fbd8d62f4d214514af4f348faa6824d12..eac8f4c7f31d8a7b10916a5cbbc5415b061db88a 100644 (file)
@@ -636,6 +636,11 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) {
       "template <typename T>\n"
       "void looooooooooooooooooooongFunction(int Paaaaaaaaaaaaaaaaaaaaram1,\n"
       "                                      int Paaaaaaaaaaaaaaaaaaaaram2);");
+  verifyFormat(
+      "template <typename T>\n"
+      "aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaa,\n"
+      "                    aaaaaaaaaaaaaaaaaaaaaaaaaa<T>::aaaaaaaaaa,\n"
+      "                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
 
 }