clang-format: If in doubt, assume '+' is a binary operator.

Before:
  #define LENGTH(x, y) (x) - (y)+1

After:
  #define LENGTH(x, y) (x) - (y) + 1

llvm-svn: 219119
This commit is contained in:
Daniel Jasper 2014-10-06 13:16:43 +00:00
parent a117002d93
commit a45eb4c000
2 changed files with 5 additions and 3 deletions

View File

@ -902,8 +902,9 @@ private:
if (Prev && Tok.Next && Tok.Next->Next) {
bool NextIsUnary = Tok.Next->isUnaryOperator() ||
Tok.Next->isOneOf(tok::amp, tok::star);
IsCast = NextIsUnary && Tok.Next->Next->isOneOf(
tok::identifier, tok::numeric_constant);
IsCast =
NextIsUnary && !Tok.Next->is(tok::plus) &&
Tok.Next->Next->isOneOf(tok::identifier, tok::numeric_constant);
}
for (; Prev != Tok.MatchingParen; Prev = Prev->Previous) {

View File

@ -5116,6 +5116,7 @@ TEST_F(FormatTest, FormatsCasts) {
verifyFormat("my_int a = (my_int)sizeof(int);");
verifyFormat("return (my_int)aaa;");
verifyFormat("#define x ((int)-1)");
verifyFormat("#define LENGTH(x, y) (x) - (y) + 1");
verifyFormat("#define p(q) ((int *)&q)");
verifyFormat("fn(a)(b) + 1;");
@ -5123,7 +5124,7 @@ TEST_F(FormatTest, FormatsCasts) {
verifyFormat("void f() { return P ? (my_int)*P : (my_int)0; }");
verifyFormat("my_int a = (my_int)~0;");
verifyFormat("my_int a = (my_int)++a;");
verifyFormat("my_int a = (my_int)+2;");
verifyFormat("my_int a = (my_int)-2;");
verifyFormat("my_int a = (my_int)1;");
verifyFormat("my_int a = (my_int *)1;");
verifyFormat("my_int a = (const my_int)-1;");