This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Go patch committed: Don't compare structs with blank non-comp fields
- From: Ian Lance Taylor <iant at google dot com>
- To: gcc-patches at gcc dot gnu dot org, gofrontend-dev at googlegroups dot com
- Date: Thu, 12 Dec 2013 10:45:26 -0800
- Subject: Go patch committed: Don't compare structs with blank non-comp fields
- Authentication-results: sourceware.org; auth=none
The Go language spec was clarified to say that a struct with a blank
field of non-comparable type may not be compared. This patch implements
that restriction in the Go frontend, by removing the code that permitted
it. This change requires a couple of test cases to be updated; I've
simply copied in the current versions of those test cases from the
master testsuite. Bootstrapped and ran Go tests on
x86_64-unknown-linux-gnu. Committed to mainline.
Ian
Index: gcc/go/gofrontend/types.cc
===================================================================
--- gcc/go/gofrontend/types.cc (revision 205916)
+++ gcc/go/gofrontend/types.cc (working copy)
@@ -575,9 +575,6 @@ Type::are_compatible_for_comparison(bool
p != fields->end();
++p)
{
- if (Gogo::is_sink_name(p->field_name()))
- continue;
-
if (!p->type()->is_comparable())
{
if (reason != NULL)
Index: gcc/testsuite/go.test/test/cmp.go
===================================================================
--- gcc/testsuite/go.test/test/cmp.go (revision 205904)
+++ gcc/testsuite/go.test/test/cmp.go (working copy)
@@ -43,8 +43,8 @@ func main() {
var d string = "hel" // try to get different pointer
d = d + "lo"
- // exp/ssa/interp can't handle unsafe.Pointer.
- if os.Getenv("GOSSAINTERP") != "" {
+ // go.tools/ssa/interp can't handle unsafe.Pointer.
+ if os.Getenv("GOSSAINTERP") == "" {
if stringptr(c) == stringptr(d) {
panic("compiler too smart -- got same string")
}
@@ -296,7 +296,7 @@ func main() {
{
var x = struct {
x int
- _ []int
+ _ string
y float64
_ float64
z int
Index: gcc/testsuite/go.test/test/cmp6.go
===================================================================
--- gcc/testsuite/go.test/test/cmp6.go (revision 205904)
+++ gcc/testsuite/go.test/test/cmp6.go (working copy)
@@ -53,7 +53,7 @@ func main() {
// Comparison of structs should have a good message
use(t3 == t3) // ERROR "struct|expected"
- use(t4 == t4) // ok; the []int is a blank field
+ use(t4 == t4) // ERROR "cannot be compared|non-comparable"
// Slices, functions, and maps too.
var x []int