aboutsummaryrefslogtreecommitdiff
path: root/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2013-01-17 17:17:19 +0000
committerNico Weber <nicolasweber@gmx.de>2013-01-17 17:17:19 +0000
commit5096a44f2ec5ab9e5b801424e04919f4fcf29f1d (patch)
treee75da440ce1b84aeb3908aecdaf9a4e9510aaa2a /unittests/Format/FormatTest.cpp
parent21937c6f1fd277b0b61e2621256c15ca3a6b0cc6 (diff)
Formatter: Get bit tests in ifs right.
It's generally not possible to know if 'a' '*' 'b' is a multiplication expression or a variable declaration with a purely lexer-based approach. The formatter currently uses a heuristic that classifies this token sequence as a multiplication in rhs contexts (after '=' or 'return') and as a declaration else. Because of this, it gets bit tests in ifs, such as "if (a & b)" wrong. However, declarations in ifs always have to be followed by '=', so this patch changes the formatter to classify '&' as an operator if it's at the start of an if statement. Before: if (a& b) if (int* b = f()) Now: if (a & b) if (int* b = f()) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172731 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r--unittests/Format/FormatTest.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 28d9fbe4e2..7b57e858a4 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1235,6 +1235,14 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
" *A, // Operator detection might be confused by the '{'\n"
" *BB // Operator detection might be confused by previous comment\n"
"};");
+
+ verifyFormat("if (int *a = &b)");
+ verifyFormat("if (int &a = *b)");
+ verifyFormat("if (a & b[i])");
+ verifyFormat("if (a::b::c::d & b[i])");
+ verifyFormat("if (*b[i])");
+ verifyFormat("if (int *a = (&b))");
+ verifyFormat("while (int *a = &b)");
}
TEST_F(FormatTest, FormatsCasts) {