aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Format/Format.cpp3
-rw-r--r--unittests/Format/FormatTest.cpp6
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index d354078231..c08bcf4f5c 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -852,7 +852,8 @@ private:
const Token &PreviousTok = Line.Tokens[Index - 1].Tok;
if (PreviousTok.is(tok::equal) || PreviousTok.is(tok::l_paren) ||
PreviousTok.is(tok::comma) || PreviousTok.is(tok::l_square) ||
- PreviousTok.is(tok::question) || PreviousTok.is(tok::colon))
+ PreviousTok.is(tok::question) || PreviousTok.is(tok::colon) ||
+ PreviousTok.is(tok::kw_return) || PreviousTok.is(tok::kw_case))
return TokenAnnotation::TT_UnaryOperator;
// There can't be to consecutive binary operators.
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 58712ef38f..22da93ebe3 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -646,6 +646,12 @@ TEST_F(FormatTest, UnderstandsUnaryOperators) {
verifyFormat("b ? -a : c;");
verifyFormat("n * sizeof char16;");
verifyFormat("sizeof(char);");
+
+ verifyFormat("return -1;");
+ verifyFormat("switch (a) {\n"
+ "case -1:\n"
+ " break;\n"
+ "}");
}
TEST_F(FormatTest, UndestandsOverloadedOperators) {