diff options
| author | Daniel Jasper <djasper@google.com> | 2013-09-14 08:13:22 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2013-09-14 08:13:22 +0000 |
| commit | 5c9e3cdb6df720d78180137bfef311b55a3186b0 (patch) | |
| tree | d7cf5bf38f2b188d9ffea81bc657905d27416074 /clang | |
| parent | fc26cfcde7161a0366fb64aabb54195a19d6083a (diff) | |
| download | bcm5719-llvm-5c9e3cdb6df720d78180137bfef311b55a3186b0.tar.gz bcm5719-llvm-5c9e3cdb6df720d78180137bfef311b55a3186b0.zip | |
clang-format: Fix bug in style option AlwaysBreakTemplateDeclarations.
Before:
template <template <typename>
class Fooooooo, template <typename>
class Baaaaaaar>
struct C {};
After:
template <template <typename> class Fooooooo,
template <typename> class Baaaaaaar>
struct C {};
llvm-svn: 190747
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 3 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 22 |
2 files changed, 16 insertions, 9 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index db17135a0c7..f9b795ece90 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 6d504c0c786..020f4480330 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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) { |

