From 5eda31ee30106c769b5829683761d42e6e50467f Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 2 Jan 2013 18:30:06 +0000 Subject: [PATCH] Don't allow line breaks after template parameters. 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 aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaa ::aaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: template aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaa::aaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171400 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/Format.cpp | 3 +++ unittests/Format/FormatTest.cpp | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 3c337ec063..6fb75a657a 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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; } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 574d685fbd..eac8f4c7f3 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -636,6 +636,11 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) { "template \n" "void looooooooooooooooooooongFunction(int Paaaaaaaaaaaaaaaaaaaaram1,\n" " int Paaaaaaaaaaaaaaaaaaaaram2);"); + verifyFormat( + "template \n" + "aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaa,\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaa::aaaaaaaaaa,\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);"); } -- 2.50.1