The Go language was tweaked to permit logical operators to return an
untyped boolean value, which means that code like
    type myBool bool
    var b myBool = a < b || c < d
is now permitted (previously the || operator would return the named
type "bool" and an explicit conversion was required for this code).

This patch from Chris Manghane implements this in gccgo, simply by
removing the old code that prevented it from working.  This requires
adjusting one existing testcase.  This is http://golang.org/issue/6671
.

Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian
Index: gcc/go/gofrontend/expressions.cc
===================================================================
--- gcc/go/gofrontend/expressions.cc    (revision 217049)
+++ gcc/go/gofrontend/expressions.cc    (working copy)
@@ -5314,15 +5314,6 @@ Binary_expression::do_determine_type(con
       subcontext.type = NULL;
     }
 
-  if (this->op_ == OPERATOR_ANDAND || this->op_ == OPERATOR_OROR)
-    {
-      // For a logical operation, the context does not determine the
-      // types of the operands.  The operands must be some boolean
-      // type but if the context has a boolean type they do not
-      // inherit it.  See http://golang.org/issue/3924.
-      subcontext.type = NULL;
-    }
-
   // Set the context for the left hand operand.
   if (is_shift_op)
     {
Index: gcc/testsuite/go.test/test/fixedbugs/issue3924.go
===================================================================
--- gcc/testsuite/go.test/test/fixedbugs/issue3924.go   (revision 217049)
+++ gcc/testsuite/go.test/test/fixedbugs/issue3924.go   (working copy)
@@ -1,4 +1,4 @@
-// errorcheck
+// compile
 
 // Copyright 2012 The Go Authors.  All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -9,5 +9,5 @@ package foo
 type mybool bool
 
 var x, y = 1, 2
-var _ mybool = x < y && x < y // ERROR "cannot use"
-var _ mybool = x < y || x < y // ERROR "cannot use"
+var _ mybool = x < y && x < y
+var _ mybool = x < y || x < y

Reply via email to