diff options
| author | Nico Weber <nicolasweber@gmx.de> | 2013-01-07 16:36:17 +0000 |
|---|---|---|
| committer | Nico Weber <nicolasweber@gmx.de> | 2013-01-07 16:36:17 +0000 |
| commit | d5650bdc1a4bcd4806631781a33ff10e87da33b5 (patch) | |
| tree | 12c6afb960a577fb901bb25fa66b6ee92c4fb58a /clang | |
| parent | e89c42f4093ae226e041a685d9bd9ac91398b843 (diff) | |
| download | bcm5719-llvm-d5650bdc1a4bcd4806631781a33ff10e87da33b5.tar.gz bcm5719-llvm-d5650bdc1a4bcd4806631781a33ff10e87da33b5.zip | |
Formatter: Add tests for try/catch. Let 'throw' start an expression.
Before:
throw a *b;
Now:
throw a * b;
llvm-svn: 171754
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Format/Format.cpp | 5 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 40 |
2 files changed, 42 insertions, 3 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 8faa93cdc7c..7a6b6e2081b 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -808,9 +808,8 @@ private: TokenAnnotation &Annotation = Annotations[i]; const FormatToken &Tok = Line.Tokens[i]; - if (getPrecedence(Tok) == prec::Assignment) - IsRHS = true; - else if (Tok.Tok.is(tok::kw_return)) + if (getPrecedence(Tok) == prec::Assignment || + Tok.Tok.is(tok::kw_return) || Tok.Tok.is(tok::kw_throw)) IsRHS = true; if (Annotation.Type != TT_Unknown) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 17e98741fd9..d4490dddfc3 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -377,6 +377,46 @@ TEST_F(FormatTest, FormatsNamespaces) { "}"); } +TEST_F(FormatTest, FormatTryCatch) { + verifyFormat("try {\n" + " throw a * b;\n" + "}\n" + "catch (int a) {\n" + " // Do nothing.\n" + "}\n" + "catch (...) {\n" + " exit(42);\n" + "}"); + + // Function-level try statements. + verifyFormat("int f() try {\n" + " return 4;\n" + "}\n" + "catch (...) {\n" + " return 5;\n" + "}"); + verifyFormat("class A {\n" + " int a;\n" + " A() try : a(0) {\n" + " }\n" + " catch (...) {\n" + " throw;\n" + " }\n" + "};\n"); +} + +TEST_F(FormatTest, FormatObjCTryCatch) { + verifyFormat("@try {\n" + " f();\n" + "}\n" + "@catch (NSException e) {\n" + " @throw;\n" + "}\n" + "@finally {\n" + " exit(42);\n" + "}"); +} + TEST_F(FormatTest, StaticInitializers) { verifyFormat("static SomeClass SC = { 1, 'a' };"); |

