]> granicus.if.org Git - clang/commitdiff
clang-format: Fix bug in style option AlwaysBreakTemplateDeclarations.
authorDaniel Jasper <djasper@google.com>
Sat, 14 Sep 2013 08:13:22 +0000 (08:13 +0000)
committerDaniel Jasper <djasper@google.com>
Sat, 14 Sep 2013 08:13:22 +0000 (08:13 +0000)
Before:
  template <template <typename>
            class Fooooooo, template <typename>
            class Baaaaaaar>
  struct C {};

After:
  template <template <typename> class Fooooooo,
            template <typename> class Baaaaaaar>
  struct C {};

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

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

index db17135a0c7438ba6c458fcd16c2b6c9dc7b7422..f9b795ece90ec25f1e84b3a84bc523b93b7a1505 100644 (file)
@@ -1052,7 +1052,10 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) {
                Current->Next->is(tok::string_literal)) {
       Current->MustBreakBefore = true;
     } else if (Current->Previous->ClosesTemplateDeclaration &&
+               Current->Previous->MatchingParen &&
+               Current->Previous->MatchingParen->BindingStrength == 1 &&
                Style.AlwaysBreakTemplateDeclarations) {
+      // FIXME: Fix horrible hack of using BindingStrength to find top-level <>.
       Current->MustBreakBefore = true;
     } else if (Current->Type == TT_CtorInitializerComma &&
                Style.BreakConstructorInitializersBeforeComma) {
index 6d504c0c786914e1f3cfe20ea14586436f837aed..020f44803301dc3631bc862c5ea42f679caba846 100644 (file)
@@ -3519,15 +3519,6 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) {
   verifyFormat("template <typename T> class C {};");
   verifyFormat("template <typename T> void f();");
   verifyFormat("template <typename T> void f() {}");
-
-  FormatStyle AlwaysBreak = getLLVMStyle();
-  AlwaysBreak.AlwaysBreakTemplateDeclarations = true;
-  verifyFormat("template <typename T>\nclass C {};", AlwaysBreak);
-  verifyFormat("template <typename T>\nvoid f();", AlwaysBreak);
-  verifyFormat("template <typename T>\nvoid f() {}", AlwaysBreak);
-  verifyFormat("void aaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
-               "                         bbbbbbbbbbbbbbbbbbbbbbbbbbbb>(\n"
-               "    ccccccccccccccccccccccccccccccccccccccccccccccc);");
   verifyFormat(
       "aaaaaaaaaaaaa<aaaaaaaaaa, aaaaaaaaaaa,\n"
       "              aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
@@ -3537,6 +3528,19 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) {
       "                      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>(\n"
       "        bbbbbbbbbbbbbbbbbbbbbbbb);",
       getLLVMStyleWithColumns(72));
+
+  FormatStyle AlwaysBreak = getLLVMStyle();
+  AlwaysBreak.AlwaysBreakTemplateDeclarations = true;
+  verifyFormat("template <typename T>\nclass C {};", AlwaysBreak);
+  verifyFormat("template <typename T>\nvoid f();", AlwaysBreak);
+  verifyFormat("template <typename T>\nvoid f() {}", AlwaysBreak);
+  verifyFormat("void aaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+               "                         bbbbbbbbbbbbbbbbbbbbbbbbbbbb>(\n"
+               "    ccccccccccccccccccccccccccccccccccccccccccccccc);");
+  verifyFormat("template <template <typename> class Fooooooo,\n"
+               "          template <typename> class Baaaaaaar>\n"
+               "struct C {};",
+               AlwaysBreak);
 }
 
 TEST_F(FormatTest, WrapsAtNestedNameSpecifiers) {