clang-format: Fix indentation of struct definitions with array init.

Before:
  struct {
    int x;
    int y;
  } points[] = {
        {1, 2}, {2, 3},
  };

After:
  struct {
    int x;
    int y;
  } points[] = {
      {1, 2}, {2, 3},
  };

llvm-svn: 220195
This commit is contained in:
Daniel Jasper 2014-10-20 11:12:51 +00:00
parent fce039240a
commit 86296e36d7
2 changed files with 12 additions and 6 deletions

View File

@ -1035,11 +1035,7 @@ static int PrecedenceArrowAndPeriod = prec::PointerToMember + 2;
/// operator precedence. /// operator precedence.
class ExpressionParser { class ExpressionParser {
public: 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. /// \brief Parse expressions with the given operatore precedence.
void parse(int Precedence = 0) { void parse(int Precedence = 0) {
@ -1086,7 +1082,7 @@ public:
// At the end of the line or when an operator with higher precedence is // At the end of the line or when an operator with higher precedence is
// found, insert fake parenthesis and return. // found, insert fake parenthesis and return.
if (!Current || Current->closesScope() || if (!Current || (Current->closesScope() && Current->MatchingParen) ||
(CurrentPrecedence != -1 && CurrentPrecedence < Precedence)) { (CurrentPrecedence != -1 && CurrentPrecedence < Precedence)) {
if (LatestOperator) { if (LatestOperator) {
LatestOperator->LastOperator = true; LatestOperator->LastOperator = true;

View File

@ -2311,6 +2311,16 @@ TEST_F(FormatTest, NestedStaticInitializers) {
" {kOsWin, \"Windows\"},\n" " {kOsWin, \"Windows\"},\n"
" {kOsLinux, \"Linux\"},\n" " {kOsLinux, \"Linux\"},\n"
" {kOsCrOS, \"Chrome OS\"}};"); " {kOsCrOS, \"Chrome OS\"}};");
verifyFormat(
"struct {\n"
" unsigned bit;\n"
" const char *const name;\n"
"} kBitsToOs[] = {\n"
" {kOsMac, \"Mac\"},\n"
" {kOsWin, \"Windows\"},\n"
" {kOsLinux, \"Linux\"},\n"
" {kOsCrOS, \"Chrome OS\"},\n"
"};");
} }
TEST_F(FormatTest, FormatsSmallMacroDefinitionsInSingleLine) { TEST_F(FormatTest, FormatsSmallMacroDefinitionsInSingleLine) {