In Go a type conversion of a constant is not necessarily itself a
constant, as in []byte(nil).  This patch fixes the Go frontend to
recognize that.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.  Will commit to 4.8
branch when it reopens.

Ian

diff -r a6f45afcc8a6 go/expressions.cc
--- a/go/expressions.cc	Wed Oct 09 15:28:49 2013 -0700
+++ b/go/expressions.cc	Wed Oct 09 17:02:02 2013 -0700
@@ -3055,8 +3055,7 @@
   do_lower(Gogo*, Named_object*, Statement_inserter*, int);
 
   bool
-  do_is_constant() const
-  { return this->expr_->is_constant(); }
+  do_is_constant() const;
 
   bool
   do_numeric_constant_value(Numeric_constant*) const;
@@ -3198,6 +3197,27 @@
   return this;
 }
 
+// Return whether a type conversion is a constant.
+
+bool
+Type_conversion_expression::do_is_constant() const
+{
+  if (!this->expr_->is_constant())
+    return false;
+
+  // A conversion to a type that may not be used as a constant is not
+  // a constant.  For example, []byte(nil).
+  Type* type = this->type_;
+  if (type->integer_type() == NULL
+      && type->float_type() == NULL
+      && type->complex_type() == NULL
+      && !type->is_boolean_type()
+      && !type->is_string_type())
+    return false;
+
+  return true;
+}
+
 // Return the constant numeric value if there is one.
 
 bool

Reply via email to