From 20545fd4b187d47d93f5229a292fb232e4d57936 Mon Sep 17 00:00:00 2001
From: Roberto Raggi <roberto.raggi@nokia.com>
Date: Fri, 19 Jun 2009 12:39:11 +0200
Subject: [PATCH] Fixed more template-id vs expressions ambiguites.

---
 src/shared/cplusplus/Parser.cpp      | 10 +++++++---
 tests/auto/cplusplus/ast/tst_ast.cpp | 11 +++++++++++
 tests/manual/cplusplus/main.cpp      |  4 ++--
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/shared/cplusplus/Parser.cpp b/src/shared/cplusplus/Parser.cpp
index e987d4d2fc0..e46f4bbae93 100644
--- a/src/shared/cplusplus/Parser.cpp
+++ b/src/shared/cplusplus/Parser.cpp
@@ -2927,7 +2927,8 @@ bool Parser::parseNameId(NameAST *&name)
     TemplateIdAST *template_id = name->asTemplateId();
     if (LA() == T_LPAREN && template_id) {
         if (TemplateArgumentListAST *template_arguments = template_id->template_arguments) {
-            if (! template_arguments->next && template_arguments->template_argument && template_arguments->template_argument->asBinaryExpression()) {
+            if (! template_arguments->next && template_arguments->template_argument &&
+                    template_arguments->template_argument->asBinaryExpression()) {
                 unsigned saved = cursor();
                 ExpressionAST *expr = 0;
                 bool blocked = blockErrors(true);
@@ -2949,13 +2950,16 @@ bool Parser::parseNameId(NameAST *&name)
         }
     }
 
-    if (LA() == T_IDENTIFIER ||
+    if (LA() == T_COMMA || LA() == T_SEMICOLON ||
+        LA() == T_LBRACKET || LA() == T_LPAREN)
+        return true;
+    else if (LA() == T_IDENTIFIER ||
         LA() == T_STATIC_CAST ||
         LA() == T_DYNAMIC_CAST ||
         LA() == T_REINTERPRET_CAST ||
         LA() == T_CONST_CAST ||
         tok().isLiteral()    ||
-        (tok().isOperator() && LA() != T_LPAREN && LA() != T_LBRACKET))
+        tok().isOperator())
     {
         rewind(start);
         return parseName(name, false);
diff --git a/tests/auto/cplusplus/ast/tst_ast.cpp b/tests/auto/cplusplus/ast/tst_ast.cpp
index 10bf85f860c..cad9d51cacc 100644
--- a/tests/auto/cplusplus/ast/tst_ast.cpp
+++ b/tests/auto/cplusplus/ast/tst_ast.cpp
@@ -45,6 +45,7 @@ private slots:
     void new_expression_1();
     void new_expression_2();
     void condition_1();
+    void init_1();
 
     // statements
     void if_statement();
@@ -157,6 +158,16 @@ void tst_AST::condition_1()
     QVERIFY(ast != 0);
 }
 
+void tst_AST::init_1()
+{
+    QSharedPointer<TranslationUnit> unit(parseDeclaration("\n"
+                                                          "x y[] = { X<10>, y };"
+    ));
+
+    AST *ast = unit->ast();
+    QVERIFY(ast != 0);
+}
+
 void tst_AST::if_statement()
 {
     QSharedPointer<TranslationUnit> unit(parseStatement("if (a) b;"));
diff --git a/tests/manual/cplusplus/main.cpp b/tests/manual/cplusplus/main.cpp
index e704400ed6c..b352034b943 100644
--- a/tests/manual/cplusplus/main.cpp
+++ b/tests/manual/cplusplus/main.cpp
@@ -552,10 +552,10 @@ int main(int argc, char *argv[])
     TranslationUnitAST *ast = unit.ast()->asTranslationUnit();
     Q_ASSERT(ast != 0);
 
-    Scope globalScope;
+    Namespace *globalNamespace = control.newNamespace(0, 0);
     Semantic sem(&control);
     for (DeclarationListAST *decl = ast->declarations; decl; decl = decl->next) {
-        sem.check(decl->declaration, &globalScope);
+        sem.check(decl->declaration, globalNamespace->members());
     }
 
     // test the rewriter
-- 
GitLab