summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/Format.cpp5
-rw-r--r--clang/unittests/Format/FormatTest.cpp2
2 files changed, 6 insertions, 1 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 548bdee2b2d..57e9a769892 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1060,7 +1060,10 @@ private:
/// \brief Determine whether ++/-- are pre- or post-increments/-decrements.
TokenType determineIncrementUsage(const AnnotatedToken &Tok) {
- if (Tok.Parent != NULL && Tok.Parent->is(tok::identifier))
+ if (Tok.Parent == NULL)
+ return TT_UnaryOperator;
+ if (Tok.Parent->is(tok::r_paren) || Tok.Parent->is(tok::r_square) ||
+ Tok.Parent->is(tok::identifier))
return TT_TrailingUnaryOperator;
return TT_UnaryOperator;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index eb87a3b9657..9565e3a8553 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -978,6 +978,8 @@ TEST_F(FormatTest, UnderstandsUnaryOperators) {
verifyFormat("if (i < -1) {}");
verifyFormat("++(a->f());");
verifyFormat("--(a->f());");
+ verifyFormat("(a->f())++;");
+ verifyFormat("a[42]++;");
verifyFormat("if (!(a->f())) {}");
verifyFormat("a-- > b;");
OpenPOWER on IntegriCloud