[cfe-commits] [PATCH] Clang-format: detect unbalanced braces.

Alexander Kornienko alexfh at google.com
Wed Dec 5 09:34:57 PST 2012


Hi klimek, djasper,

http://llvm-reviews.chandlerc.com/D176

Files:
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTest.cpp

Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -52,8 +52,8 @@
       addUnwrappedLine();
       break;
     case tok::r_brace:
-      // FIXME: We need a test when it has to be "return Error;"
-      return false;
+      // Stray '}' is an error.
+      return true;
     default:
       parseStatement();
       break;
@@ -63,6 +63,7 @@
 }
 
 bool UnwrappedLineParser::parseBlock() {
+  assert(FormatTok.Tok.is(tok::l_brace) && "'{' expected");
   nextToken();
 
   // FIXME: Remove this hack to handle namespaces.
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -420,6 +420,7 @@
   EXPECT_EQ("{\n{\n}\n", format("{\n{\n}\n"));
   EXPECT_EQ("{\n  {\n}\n", format("{\n  {\n}\n"));
   EXPECT_EQ("{\n  {\n  }\n", format("{\n  {\n  }\n"));
+  EXPECT_EQ("{\n  {\n    }\n  }\n}\n", format("{\n  {\n    }\n  }\n}\n"));
 
   FormatStyle Style = getLLVMStyle();
   Style.ColumnLimit = 10;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D176.1.patch
Type: text/x-patch
Size: 1159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121205/9c67de15/attachment.bin>


More information about the cfe-commits mailing list