aboutsummaryrefslogtreecommitdiff
path: root/gcc/go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2013-10-11 17:45:29 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2013-10-11 17:45:29 +0000
commit0213a547b0ec72dbd0ea3e98181c9ebc20275a92 (patch)
tree1c6584a26684533c45df878420d1189e72daa251 /gcc/go
parent8d28e3fc183b10b3c74240d87ec375233e31f3e7 (diff)
downloadgcc-0213a547b0ec72dbd0ea3e98181c9ebc20275a92.zip
gcc-0213a547b0ec72dbd0ea3e98181c9ebc20275a92.tar.gz
gcc-0213a547b0ec72dbd0ea3e98181c9ebc20275a92.tar.bz2
compiler: accept integral float constants as string indices.
From-SVN: r203452
Diffstat (limited to 'gcc/go')
-rw-r--r--gcc/go/gofrontend/expressions.cc13
1 files changed, 11 insertions, 2 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 37f8822..06c3429 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -10888,11 +10888,20 @@ String_index_expression::do_determine_type(const Type_context*)
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;