From b9c0908f7c7770c38e51bd8b023b5792a3b60c56 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 23 Jan 2013 11:15:14 +0000 Subject: [PATCH] Fix regression in formatting pointer types. We will need a more principled solution, but we should not leave this unfixed until we come up with one. Before: void f() { int * a; } After: void f() { int *a; } llvm-svn: 173252 --- clang/lib/Format/Format.cpp | 4 +++- clang/unittests/Format/FormatTest.cpp | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 90bcf6f..36bf53d 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1260,6 +1260,8 @@ private: if (getPrecedence(Current) == prec::Assignment || Current.is(tok::kw_return) || Current.is(tok::kw_throw)) IsRHS = true; + if (Current.is(tok::l_paren) && !Line.MustBeDeclaration) + IsRHS = true; if (Current.Type == TT_Unknown) { if (Current.is(tok::star) || Current.is(tok::amp)) { @@ -1370,7 +1372,7 @@ private: // It is very unlikely that we are going to find a pointer or reference type // definition on the RHS of an assignment. - if (IsRHS || !Line.MustBeDeclaration) + if (IsRHS) return TT_BinaryOperator; return TT_PointerOrReference; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 114359d..44f91c7 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -1288,6 +1288,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyFormat("int a = *b;"); verifyFormat("int a = *b * c;"); verifyFormat("int a = b * *c;"); + verifyFormat("void f() { int *a = b * c; }"); verifyFormat("int main(int argc, char **argv) {}"); verifyFormat("return 10 * b;"); verifyFormat("return *b * *c;"); -- 2.7.4