In Go you can not indirect through an unsafe.Pointer type.  You have to
convert it to some real pointer type first.  This patch to the Go
frontend gives a better error for trying to do this, rather than trying
to handle the void type in other places.  Bootstrapped and ran Go
testsuite on x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

diff -r b426ff8fb580 go/expressions.cc
--- a/go/expressions.cc	Sat Mar 26 12:04:00 2011 -0700
+++ b/go/expressions.cc	Sat Mar 26 22:33:57 2011 -0700
@@ -3669,6 +3669,14 @@
 	}
     }
 
+  // Catching an invalid indirection of unsafe.Pointer here avoid
+  // having to deal with TYPE_VOID in other places.
+  if (op == OPERATOR_MULT && expr->type()->is_unsafe_pointer_type())
+    {
+      error_at(this->location(), "invalid indirect of %<unsafe.Pointer%>");
+      return Expression::make_error(this->location());
+    }
+
   if (op == OPERATOR_PLUS || op == OPERATOR_MINUS
       || op == OPERATOR_NOT || op == OPERATOR_XOR)
     {

Reply via email to