clang-format: Support chained dereferenced assignments.

Before:
  x = * a(x) = *a(y);

After:
  x = *a(x) = *a(y);

llvm-svn: 215632
This commit is contained in:
Daniel Jasper 2014-08-14 10:53:19 +00:00
parent 78b4533acf
commit 1904e9b98d
2 changed files with 6 additions and 1 deletions

View File

@ -708,7 +708,8 @@ private:
}
if ((Previous->Type == TT_BinaryOperator ||
Previous->Type == TT_UnaryOperator) &&
Previous->isOneOf(tok::star, tok::amp)) {
Previous->isOneOf(tok::star, tok::amp) && Previous->Previous &&
Previous->Previous->isNot(tok::equal)) {
Previous->Type = TT_PointerOrReference;
}
}

View File

@ -4823,6 +4823,10 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
"const char* const p = reinterpret_cast<const char* const>(q);");
verifyGoogleFormat("void f(int i = 0, SomeType** temps = NULL);");
FormatStyle Left = getLLVMStyle();
Left.PointerAlignment = FormatStyle::PAS_Left;
verifyFormat("x = *a(x) = *a(y);", Left);
verifyIndependentOfContext("a = *(x + y);");
verifyIndependentOfContext("a = &(x + y);");
verifyIndependentOfContext("*(x + y).call();");