[cfe-commits] r171389 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp
Daniel Jasper
djasper at google.com
Wed Jan 2 07:26:19 PST 2013
Author: djasper
Date: Wed Jan 2 09:26:16 2013
New Revision: 171389
URL: http://llvm.org/viewvc/llvm-project?rev=171389&view=rev
Log:
Understand unary operators after "return" and "case".
This fixes llvm.org/PR14746.
Before: return - 1;
After: return -1;
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=171389&r1=171388&r2=171389&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Jan 2 09:26:16 2013
@@ -852,7 +852,8 @@
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.
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=171389&r1=171388&r2=171389&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan 2 09:26:16 2013
@@ -646,6 +646,12 @@
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) {
More information about the cfe-commits
mailing list