diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-02 08:44:14 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-02 08:44:14 +0000 |
commit | 4dc41def6129bcecd4d08e5ffafe021aa7b1fa2a (patch) | |
tree | 44cd1ec13cc61341be55c5aa1223f5152a1b1c40 | |
parent | 62a833eaebb1867d9950767288debdfa34dd8561 (diff) |
Don't break after pointer or reference specifier.
This fixes llvm.org/PR14717.
Buggy format:
TypeSpecDecl *
TypeSpecDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
IdentifierInfo *II, Type *T) {
Now changed to:
TypeSpecDecl *TypeSpecDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation L, IdentifierInfo *II,
Type *T) {
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171357 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Format/Format.cpp | 11 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 10 |
2 files changed, 18 insertions, 3 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 93126613ec..a6c11dcd7a 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -660,8 +660,7 @@ public: for (int i = 1, e = Line.Tokens.size(); i != e; ++i) { TokenAnnotation &Annotation = Annotations[i]; - Annotation.CanBreakBefore = - canBreakBetween(Line.Tokens[i - 1], Line.Tokens[i]); + Annotation.CanBreakBefore = canBreakBefore(i); if (Annotation.Type == TokenAnnotation::TT_CtorInitializerColon) { Annotation.MustBreakBefore = true; @@ -896,7 +895,13 @@ private: return true; } - bool canBreakBetween(const FormatToken &Left, const FormatToken &Right) { + bool canBreakBefore(unsigned i) { + if (Annotations[i - 1].Type == TokenAnnotation::TT_PointerOrReference || + Annotations[i].Type == TokenAnnotation::TT_ConditionalExpr) { + return false; + } + const FormatToken &Left = Line.Tokens[i - 1]; + const FormatToken &Right = Line.Tokens[i]; if (Right.Tok.is(tok::r_paren) || Right.Tok.is(tok::l_brace) || Right.Tok.is(tok::comment) || Right.Tok.is(tok::greater)) return false; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index b719acfabc..99204f56f5 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -682,6 +682,16 @@ TEST_F(FormatTest, UnderstandsUsesOfStar) { verifyGoogleFormat("A<int**, int**> a;"); } +TEST_F(FormatTest, DoesNotBreakBeforePointerOrReference) { + verifyFormat( + "int *someFunction(int LoooooooooooooooongParam1,\n" + " int LoooooooooooooooongParam2) {\n}"); + verifyFormat( + "TypeSpecDecl *TypeSpecDecl::Create(ASTContext &C, DeclContext *DC,\n" + " SourceLocation L, IdentifierIn *II,\n" + " Type *T) {\n}"); +} + TEST_F(FormatTest, LineStartsWithSpecialCharacter) { verifyFormat("(a)->b();"); verifyFormat("--a;"); |