OSDN Git Service

compiler: Fix order of initialization bug with global var a, b = f().
[pf3gnuchains/gcc-fork.git] / gcc / go / gofrontend / parse.cc
index 1a9c153..6567a42 100644 (file)
@@ -1667,6 +1667,7 @@ Parse::init_vars_from_call(const Typed_identifier_list* vars, Type* type,
   // the right number of values, but it might.  Declare the variables,
   // and then assign the results of the call to them.
 
+  Named_object* first_var = NULL;
   unsigned int index = 0;
   bool any_new = false;
   for (Typed_identifier_list::const_iterator pv = vars->begin();
@@ -1674,7 +1675,22 @@ Parse::init_vars_from_call(const Typed_identifier_list* vars, Type* type,
        ++pv, ++index)
     {
       Expression* init = Expression::make_call_result(call, index);
-      this->init_var(*pv, type, init, is_coloneq, false, &any_new);
+      Named_object* no = this->init_var(*pv, type, init, is_coloneq, false,
+                                       &any_new);
+
+      if (this->gogo_->in_global_scope() && no->is_variable())
+       {
+         if (first_var == NULL)
+           first_var = no;
+         else
+           {
+             // The subsequent vars have an implicit dependency on
+             // the first one, so that everything gets initialized in
+             // the right order and so that we detect cycles
+             // correctly.
+             this->gogo_->record_var_depends_on(no->var_value(), first_var);
+           }
+       }
     }
 
   if (is_coloneq && !any_new)
@@ -2865,7 +2881,16 @@ Parse::primary_expr(bool may_be_sink, bool may_be_composite_lit,
     {
       if (this->peek_token()->is_op(OPERATOR_LCURLY))
        {
-         if (is_parenthesized)
+         if (!may_be_composite_lit)
+           {
+             Type* t = ret->type();
+             if (t->named_type() != NULL
+                 || t->forward_declaration_type() != NULL)
+               error_at(start_loc,
+                        _("parentheses required around this composite literal"
+                          "to avoid parsing ambiguity"));
+           }
+         else if (is_parenthesized)
            error_at(start_loc,
                     "cannot parenthesize type in composite literal");
          ret = this->composite_lit(ret->type(), 0, ret->location());
@@ -3971,7 +3996,7 @@ Parse::if_stat()
 
   bool saw_simple_stat = false;
   Expression* cond = NULL;
-  bool saw_send_stmt;
+  bool saw_send_stmt = false;
   if (this->simple_stat_may_start_here())
     {
       cond = this->simple_stat(false, &saw_send_stmt, NULL, NULL);