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
This commit is contained in:
Daniel Jasper 2013-06-06 09:11:58 +00:00
parent c87e009059
commit 6dcecb6b33
2 changed files with 9 additions and 1 deletions

View File

@ -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) {

View File

@ -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) {