compiler: treat S("") as a string constant
authorIan Lance Taylor <iant@golang.org>
Sun, 9 Oct 2022 19:52:17 +0000 (12:52 -0700)
committerIan Lance Taylor <iant@golang.org>
Mon, 10 Oct 2022 21:45:57 +0000 (14:45 -0700)
The compiler neglected to notice that a conversion from a string
constant to a string type was a valid string constant.

No test case because this only caused a compiler failure when compiling
without optimization, which is not the normal case, and is not a case
that we test.

Fixes golang/go#56113

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/441555

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/expressions.cc

index 1c24660..5b95b38 100644 (file)
@@ -1,4 +1,4 @@
-164f2aeb1deec4c11e55b8bfb152ff7ff4c1dd4c
+6c188108858e3ae8c8ea8e4cc55427d8cf01bbc8
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index 247ae1b..71838b1 100644 (file)
@@ -4092,6 +4092,9 @@ Type_conversion_expression::do_numeric_constant_value(
 bool
 Type_conversion_expression::do_string_constant_value(std::string* val) const
 {
+  if (this->type_->is_string_type() && this->expr_->type()->is_string_type())
+    return this->expr_->string_constant_value(val);
+
   if (this->type_->is_string_type()
       && this->expr_->type()->integer_type() != NULL)
     {