diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-10-10 00:04:23 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-10-10 00:04:23 +0000 |
commit | e7d9342c7b51b4a66d3341d53d55bc9add186c0b (patch) | |
tree | c5123176fadef40c02071fb15c24424e29e54487 /gcc/go/gofrontend | |
parent | 215552adac04bc04778b3052c24d8c66b8455fef (diff) | |
download | gcc-e7d9342c7b51b4a66d3341d53d55bc9add186c0b.zip gcc-e7d9342c7b51b4a66d3341d53d55bc9add186c0b.tar.gz gcc-e7d9342c7b51b4a66d3341d53d55bc9add186c0b.tar.bz2 |
compiler: A type conversion of a constant is not always a constant.
From-SVN: r203332
Diffstat (limited to 'gcc/go/gofrontend')
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 9d59349..e96ab76 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -3055,8 +3055,7 @@ class Type_conversion_expression : public Expression 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 @@ Type_conversion_expression::do_lower(Gogo*, Named_object*, 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 |