From 86296e36d70c585c0e8a905da1d3546c51d1a121 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 20 Oct 2014 11:12:51 +0000 Subject: [PATCH] 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 --- clang/lib/Format/TokenAnnotator.cpp | 8 ++------ clang/unittests/Format/FormatTest.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 7e589c7..ad14aab 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1035,11 +1035,7 @@ static int PrecedenceArrowAndPeriod = prec::PointerToMember + 2; /// operator precedence. class ExpressionParser { public: - ExpressionParser(AnnotatedLine &Line) : Current(Line.First) { - // Skip leading "}", e.g. in "} else if (...) {". - if (Current->is(tok::r_brace)) - next(); - } + ExpressionParser(AnnotatedLine &Line) : Current(Line.First) {} /// \brief Parse expressions with the given operatore precedence. void parse(int Precedence = 0) { @@ -1086,7 +1082,7 @@ public: // At the end of the line or when an operator with higher precedence is // found, insert fake parenthesis and return. - if (!Current || Current->closesScope() || + if (!Current || (Current->closesScope() && Current->MatchingParen) || (CurrentPrecedence != -1 && CurrentPrecedence < Precedence)) { if (LatestOperator) { LatestOperator->LastOperator = true; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index b669795..6961ab5 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -2311,6 +2311,16 @@ TEST_F(FormatTest, NestedStaticInitializers) { " {kOsWin, \"Windows\"},\n" " {kOsLinux, \"Linux\"},\n" " {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) { -- 2.7.4