summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-01-02 08:57:10 +0000
committerDaniel Jasper <djasper@google.com>2013-01-02 08:57:10 +0000
commit22bcf8a8eb12864fef50624c2fa62bc1bb354a0d (patch)
treede00e4527e3b2c7a9cb11ee3af9d2d16a2f3cc22
parentd1926a3758e9c031e4a9f48d9ccdd754e438a816 (diff)
downloadbcm5719-llvm-22bcf8a8eb12864fef50624c2fa62bc1bb354a0d.tar.gz
bcm5719-llvm-22bcf8a8eb12864fef50624c2fa62bc1bb354a0d.zip
Understand * and & in ternary expressions.
Before: "int a = b ? *c : * d;" After: "int a = b ? *c : *d; llvm-svn: 171358
-rw-r--r--clang/lib/Format/Format.cpp1
-rw-r--r--clang/unittests/Format/FormatTest.cpp6
2 files changed, 6 insertions, 1 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index a6c11dcd7ad..b304e2bf3d7 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -806,6 +806,7 @@ private:
if (Index == 0 || Line.Tokens[Index - 1].Tok.is(tok::l_paren) ||
Line.Tokens[Index - 1].Tok.is(tok::comma) ||
Line.Tokens[Index - 1].Tok.is(tok::kw_return) ||
+ Line.Tokens[Index - 1].Tok.is(tok::colon) ||
Annotations[Index - 1].Type == TokenAnnotation::TT_BinaryOperator)
return TokenAnnotation::TT_UnaryOperator;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 99204f56f58..5dcd2d1bad1 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -650,7 +650,7 @@ TEST_F(FormatTest, UndestandsOverloadedOperators) {
verifyFormat("void operator delete[](void *ptr);");
}
-TEST_F(FormatTest, UnderstandsUsesOfStar) {
+TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyFormat("int *f(int *a) {\n}");
verifyFormat("f(a, *a);");
verifyFormat("f(*a);");
@@ -668,6 +668,8 @@ TEST_F(FormatTest, UnderstandsUsesOfStar) {
verifyFormat("return 10 * b;");
verifyFormat("return *b * *c;");
verifyFormat("return a & ~b;");
+ verifyFormat("f(b ? *c : *d);");
+ verifyFormat("int a = b ? *c : *d;");
// FIXME: Is this desired for LLVM? Fix if not.
verifyFormat("A<int *> a;");
@@ -680,6 +682,8 @@ TEST_F(FormatTest, UnderstandsUsesOfStar) {
verifyGoogleFormat("A<int**> a;");
verifyGoogleFormat("A<int*, int*> a;");
verifyGoogleFormat("A<int**, int**> a;");
+ verifyGoogleFormat("f(b ? *c : *d);");
+ verifyGoogleFormat("int a = b ? *c : *d;");
}
TEST_F(FormatTest, DoesNotBreakBeforePointerOrReference) {
OpenPOWER on IntegriCloud