diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-02 15:26:16 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-02 15:26:16 +0000 |
commit | da1c68ab715c779c6a6d87765ffc3fd83403765d (patch) | |
tree | 03a9292acc409a58f43f25a3e661058a09c27a91 /clang | |
parent | ac5c1c286cbc0b00b977544dc69ddde299f8db0e (diff) | |
download | bcm5719-llvm-da1c68ab715c779c6a6d87765ffc3fd83403765d.tar.gz bcm5719-llvm-da1c68ab715c779c6a6d87765ffc3fd83403765d.zip |
Understand unary operators after "return" and "case".
This fixes llvm.org/PR14746.
Before: return - 1;
After: return -1;
llvm-svn: 171389
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Format/Format.cpp | 3 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index d354078231c..c08bcf4f5c1 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 58712ef38fb..22da93ebe3c 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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) { |