[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/sdk/kdevelop/languages/cpp/parser
From:       Milian Wolff <mail () milianw ! de>
Date:       2010-04-06 10:54:09
Message-ID: 20100406105409.7D4ECAC7E2 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1111648 by mwolff:

support trailing commas in init lists, which is valid code as long as we are not \
pedantic

add test

BUG: 233328

 M  +6 -0      parser.cpp  
 M  +16 -0     tests/test_parser.cpp  


--- trunk/extragear/sdk/kdevelop/languages/cpp/parser/parser.cpp #1111647:1111648
@@ -2564,6 +2564,12 @@
       if (list)
         advance(); // skip ',' separator between clauses
 
+      if (session->token_stream->lookAhead() == '}') {
+        // see https://bugs.kde.org/show_bug.cgi?id=233328
+        // init lists may have a trailing comma
+        break;
+      }
+
       InitializerClauseAST *init_clause = 0;
       if (!parseInitializerClause(init_clause))
         {
--- trunk/extragear/sdk/kdevelop/languages/cpp/parser/tests/test_parser.cpp \
#1111647:1111648 @@ -407,6 +407,22 @@
     dumper.dump(ast, lastSession->token_stream);
   }
 
+  void testInitListTrailingComma()
+  {
+    //see bug https://bugs.kde.org/show_bug.cgi?id=233328
+
+    QByteArray code("const int foo [] = {1,};");
+    pool memPool;
+    TranslationUnitAST* ast = parse(code, &memPool);
+    dumper.dump(ast, lastSession->token_stream);
+
+    QCOMPARE(ast->declarations->count(), 1);
+    SimpleDeclarationAST* simpleDecl = \
reinterpret_cast<SimpleDeclarationAST*>(ast->declarations->at(0)->element); +    \
QVERIFY(simpleDecl); +
+    QCOMPARE(simpleDecl->init_declarators->count(), 1);
+  }
+
   /*void testParseFile()
   {
      QFile file(TEST_FILE);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic