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]

[gccgo] Permit omitting type in composite literal with key


Go recently changed to permit omitting the type in a composite literal,
and I fixed gccgo to support that.  However, I missed the case where the
composite literal uses a key, as in

type S struct {
	i int
}
var M = map[int]S{ 0 : { 0 }, 1 : { 1 }}

Previously this had to be

var M = map[int]S{ 0 : S{ 0 }, 1 : S{ 1 }}

This patch permits omitting the type when using a key.  Committed to
gccgo branch.

Ian

diff -r 4cabf36880e8 go/parse.cc
--- a/go/parse.cc	Wed Nov 10 14:43:00 2010 -0800
+++ b/go/parse.cc	Wed Nov 10 14:54:23 2010 -0800
@@ -2395,7 +2395,15 @@
 
 	  vals->push_back(val);
 
-	  val = this->expression(PRECEDENCE_NORMAL, false, true, NULL);
+	  if (!token->is_op(OPERATOR_LCURLY))
+	    val = this->expression(PRECEDENCE_NORMAL, false, true, NULL);
+	  else
+	    {
+	      // This must be a composite literal inside another
+	      // composite literal, with the type omitted for the
+	      // inner one.
+	      val = this->composite_lit(type, depth + 1, token->location());
+	    }
 
 	  token = this->peek_token();
 	}

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