]> granicus.if.org Git - clang/commitdiff
Fix parsing of initializer lists with elaborated type specifier.
authorManuel Klimek <klimek@google.com>
Fri, 11 Jan 2013 18:13:04 +0000 (18:13 +0000)
committerManuel Klimek <klimek@google.com>
Fri, 11 Jan 2013 18:13:04 +0000 (18:13 +0000)
Now we correctly parse and format:
verifyFormat("struct foo a = { bar };
int n;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172229 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp
lib/Format/UnwrappedLineParser.h
unittests/Format/FormatTest.cpp

index f7332ee7707c5805ee6041815ed6ec1e6d7e9780..758f8193ca4f720d4a9f105417d95cff3209b12a 100644 (file)
@@ -319,7 +319,7 @@ void UnwrappedLineParser::parseStructuralElement() {
       return;
     case tok::kw_struct:  // fallthrough
     case tok::kw_class:
-      parseStructOrClass();
+      parseStructClassOrBracedList();
       return;
     case tok::semi:
       nextToken();
@@ -565,7 +565,7 @@ void UnwrappedLineParser::parseEnum() {
   } while (!eof());
 }
 
-void UnwrappedLineParser::parseStructOrClass() {
+void UnwrappedLineParser::parseStructClassOrBracedList() {
   nextToken();
   do {
     switch (FormatTok.Tok.getKind()) {
@@ -578,6 +578,12 @@ void UnwrappedLineParser::parseStructOrClass() {
       nextToken();
       addUnwrappedLine();
       return;
+    case tok::equal:
+      nextToken();
+      if (FormatTok.Tok.is(tok::l_brace)) {
+        parseBracedList();
+      }
+      break;
     default:
       nextToken();
       break;
index 837b5391f67dab85b61af321240ea45310e1668f..cfd0608ba2e885a32b05ac8ca24b9c231a2bb20f 100644 (file)
@@ -146,7 +146,7 @@ private:
   void parseNamespace();
   void parseAccessSpecifier();
   void parseEnum();
-  void parseStructOrClass();
+  void parseStructClassOrBracedList();
   void parseObjCProtocolList();
   void parseObjCUntilAtEnd();
   void parseObjCInterfaceOrImplementation();
index a16f66cd086b55a35ae16c1f10afc2a301b4ac13..71fa83ccb1405486488fedf9a62bb8e3820c2a51 100644 (file)
@@ -1163,6 +1163,10 @@ TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {
                "}");
 }
 
+TEST_F(FormatTest, BracedInitListWithElaboratedTypeSpecifier) {
+  verifyFormat("struct foo a = { bar };\nint n;");
+}
+
 // FIXME: This breaks the order of the unwrapped lines:
 // TEST_F(FormatTest, OrderUnwrappedLines) {
 //   verifyFormat("{\n"