This patch from Rémy Oudompheng fixes the Go frontend to accept an
integral float constant as an index into a string.  That was already
fixes for arrays, but not for strings.  Bootstrapped and ran Go
testsuite on x86_64-unknown-linux-gnu.  Committed to mainline.  Will
commit to 4.8 branch when the branch opens.

Ian

diff -r 57f0ef7df750 go/expressions.cc
--- a/go/expressions.cc	Fri Oct 11 10:03:09 2013 -0700
+++ b/go/expressions.cc	Fri Oct 11 10:40:53 2013 -0700
@@ -10888,11 +10888,20 @@
 void
 String_index_expression::do_check_types(Gogo*)
 {
-  if (this->start_->type()->integer_type() == NULL)
+  Numeric_constant nc;
+  unsigned long v;
+  if (this->start_->type()->integer_type() == NULL
+      && !this->start_->type()->is_error()
+      && (!this->start_->numeric_constant_value(&nc)
+	  || nc.to_unsigned_long(&v) == Numeric_constant::NC_UL_NOTINT))
     this->report_error(_("index must be integer"));
   if (this->end_ != NULL
       && this->end_->type()->integer_type() == NULL
-      && !this->end_->is_nil_expression())
+      && !this->end_->type()->is_error()
+      && !this->end_->is_nil_expression()
+      && !this->end_->is_error_expression()
+      && (!this->end_->numeric_constant_value(&nc)
+	  || nc.to_unsigned_long(&v) == Numeric_constant::NC_UL_NOTINT))
     this->report_error(_("slice end must be integer"));
 
   std::string sval;

Reply via email to