This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Go patch committed: Permit omitting &T in composite literal


Tristan Gingold <gingold@adacore.com> writes:

> On Dec 14, 2011, at 3:48 PM, Ian Lance Taylor wrote:
>
>> The Go language was changed to permit omitting &T in composite literals,
>> as in
>> 
>> var v = []*S{ &S{0}, &S{1} }
>> 
>> This can now be written as
>> 
>> var v = []*S{ {0}, {1} }
>> 
>> This patch implements this change in the gccgo frontend.  Bootstrapped
>> and ran Go testsuite on x86_64-unknown-linux-gnu.  Committed to
>> mainline.
>
> Wrong attachment ?

Um, yeah.  Sorry.

Ian

diff -r 1b4b1984da1a -r e97b850a6f33 go/expressions.cc
--- a/go/expressions.cc	Tue Dec 13 17:33:47 2011 -0800
+++ b/go/expressions.cc	Wed Dec 14 06:46:23 2011 -0800
@@ -12783,14 +12783,23 @@
 	}
     }
 
+  Type *pt = type->points_to();
+  bool is_pointer = false;
+  if (pt != NULL)
+    {
+      is_pointer = true;
+      type = pt;
+    }
+
+  Expression* ret;
   if (type->is_error())
     return Expression::make_error(this->location());
   else if (type->struct_type() != NULL)
-    return this->lower_struct(gogo, type);
+    ret = this->lower_struct(gogo, type);
   else if (type->array_type() != NULL)
-    return this->lower_array(type);
+    ret = this->lower_array(type);
   else if (type->map_type() != NULL)
-    return this->lower_map(gogo, function, inserter, type);
+    ret = this->lower_map(gogo, function, inserter, type);
   else
     {
       error_at(this->location(),
@@ -12798,6 +12807,11 @@
 		"for composite literal"));
       return Expression::make_error(this->location());
     }
+
+  if (is_pointer)
+    ret = Expression::make_heap_composite(ret, this->location());
+
+  return ret;
 }
 
 // Lower a struct composite literal.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]