diff options
| author | Daniel Jasper <djasper@google.com> | 2013-06-06 09:11:58 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2013-06-06 09:11:58 +0000 |
| commit | 6dcecb6b33ee04a93ef4f94e8597f9b8679d1c5d (patch) | |
| tree | e257928d50f00da2b930bca4fa44b30a95295279 | |
| parent | c87e0090592667a0e37f9f1caafd15453db4c597 (diff) | |
| download | bcm5719-llvm-6dcecb6b33ee04a93ef4f94e8597f9b8679d1c5d.tar.gz bcm5719-llvm-6dcecb6b33ee04a93ef4f94e8597f9b8679d1c5d.zip | |
Fix clang-format's expression parser for leading }s.
The leading "}" in the construct "} else if (..) {" was confusing the
expression parser. Thus, no fake parentheses were generated and the
indentation was broken in some cases.
llvm-svn: 183393
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 6 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 4 |
2 files changed, 9 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index fc53681394e..71a1a28c85f 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -773,7 +773,11 @@ private: /// operator precedence. class ExpressionParser { public: - ExpressionParser(AnnotatedLine &Line) : Current(Line.First) {} + ExpressionParser(AnnotatedLine &Line) : Current(Line.First) { + // Skip leading "}", e.g. in "} else if (...) {". + if (Current->is(tok::r_brace)) + next(); + } /// \brief Parse expressions with the given operatore precedence. void parse(int Precedence = 0) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 1c2a5404091..19f702f06a6 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -2073,6 +2073,10 @@ TEST_F(FormatTest, ExpressionIndentation) { " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n" " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) {\n}"); + verifyFormat("if () {\n" + "} else if (aaaaa && bbbbb > // break\n" + " ccccc) {\n" + "}"); } TEST_F(FormatTest, ConstructorInitializers) { |

