Fixes layouting regression and invalid-read.

Layouting would prevent breaking before + in
a[b + c] = d;
Regression detected by code review.

Also fixes an invalid-read found by the valgrind bot.

llvm-svn: 173262
This commit is contained in:
Manuel Klimek 2013-01-23 14:08:21 +00:00
parent 7206a145dd
commit c1237a8b8f
3 changed files with 14 additions and 2 deletions

View File

@ -1256,8 +1256,10 @@ private:
IsExpression = true;
AnnotatedToken *Previous = Current.Parent;
while (Previous != NULL) {
if (Previous->Type == TT_BinaryOperator)
if (Previous->Type == TT_BinaryOperator &&
(Previous->is(tok::star) || Previous->is(tok::amp))) {
Previous->Type = TT_PointerOrReference;
}
Previous = Previous->Parent;
}
}

View File

@ -38,7 +38,10 @@ public:
}
~ScopedDeclarationState() {
Stack.pop_back();
Line.MustBeDeclaration = Stack.back();
if (!Stack.empty())
Line.MustBeDeclaration = Stack.back();
else
Line.MustBeDeclaration = true;
}
private:
UnwrappedLine &Line;

View File

@ -1365,6 +1365,13 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyGoogleFormat("A = new SomeType* [Length]();");
}
TEST_F(FormatTest, FormatsBinaryOperatorsPrecedingEquals) {
verifyFormat("void f() {\n"
" x[aaaaaaaaa -\n"
" b] = 23;\n"
"}", getLLVMStyleWithColumns(15));
}
TEST_F(FormatTest, FormatsCasts) {
verifyFormat("Type *A = static_cast<Type *>(P);");
verifyFormat("Type *A = (Type *)P;");