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] Better message for use of [...] outside of array literal


This patch to gccgo gives a better message for an erronsous use of [...]
outside of an array literal.  Committed to gccgo branch.

Ian

diff -r 68086824a127 go/parse.cc
--- a/go/parse.cc	Wed Sep 01 16:53:16 2010 -0700
+++ b/go/parse.cc	Wed Sep 01 17:05:42 2010 -0700
@@ -375,9 +375,9 @@
     this->advance_token();
   else
     {
-      if (!may_use_ellipsis || !token->is_op(OPERATOR_ELLIPSIS))
+      if (!token->is_op(OPERATOR_ELLIPSIS))
 	length = this->expression(PRECEDENCE_NORMAL, false, true, NULL);
-      else
+      else if (may_use_ellipsis)
 	{
 	  // An ellipsis is used in composite literals to represent a
 	  // fixed array of the size of the number of elements.  We
@@ -386,6 +386,12 @@
 	  length = Expression::make_nil(this->location());
 	  this->advance_token();
 	}
+      else
+	{
+	  this->error("use of %<[...]%> outside of array literal");
+	  length = Expression::make_error(this->location());
+	  this->advance_token();
+	}
       if (!this->peek_token()->is_op(OPERATOR_RSQUARE))
 	{
 	  this->error("expected %<]%>");
diff -r 68086824a127 go/types.cc
--- a/go/types.cc	Wed Sep 01 16:53:16 2010 -0700
+++ b/go/types.cc	Wed Sep 01 17:05:42 2010 -0700
@@ -3418,7 +3418,8 @@
     }
   else
     {
-      error_at(this->length_->location(), "array bound is not numeric");
+      if (!t->is_error_type())
+	error_at(this->length_->location(), "array bound is not numeric");
       return false;
     }
 

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