From patchwork Tue Sep 25 23:19:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 186918 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 6A3AC2C008A for ; Wed, 26 Sep 2012 09:19:25 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1349219966; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:From:To:Subject:Date:Message-ID:User-Agent: MIME-Version:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=auAReOZS0Nb8Ip/nBIvEaiBG+8c=; b=gysuF4YR5apXZY0 xwxuTe/CiFXIYSzupteDhLaYNsenbB+VLWCPsuc9YNPu3/Xt/FCuFoV7wBKeZJov GPRPwhYSCK7aTAhir0l25O7yFeV9lP/e/LOJLSeUpUm285XtERKUC0twArNtnjJv LDoJ2FoJgQlVTIn9GPW//+cJYUTg= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:Received:Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=eZqFmOrs7DY9fKQOyCinZU1f9pVfiMn9QWwy8hhhesUC7FvYW0m6/tOScImisW SpbnygHGmvkZRogMQEJJPg2nhsTUWohvfvpoO+NjgVRhUZR+sg7XX7epUfLNZNrl 7juiu3MpspH3ew+K6eu6sbOIvcm7QDlCBey2bbZKveZas=; Received: (qmail 29266 invoked by alias); 25 Sep 2012 23:19:23 -0000 Received: (qmail 29254 invoked by uid 22791); 25 Sep 2012 23:19:22 -0000 X-SWARE-Spam-Status: No, hits=-5.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mail-ob0-f175.google.com (HELO mail-ob0-f175.google.com) (209.85.214.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 25 Sep 2012 23:19:10 +0000 Received: by obceq6 with SMTP id eq6so2423048obc.20 for ; Tue, 25 Sep 2012 16:19:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type:x-gm-message-state; bh=kffMfNZYSIWYxuc4x2rv8acBD9u9AvXAi2uzUx/l5fs=; b=SpobwqWkCSy8FFIIlwVgu85jlfwnsLYCt5kc3RzRkM1tFcT8QKxM0G7Y1yoN+Sh6Qg TL3ivvbjsIVaM7P11PR0TpDC0PEzMXl4i5ifEq5peeuXhF4MHCsbQ6kbRo8w0BlwuoBp zzf0DpTeUxBRP4aoCrXL4qNpxt/iNI0Lkqqhiy6xHz/CIZQnrI37dCKuiz4B7ltzIuST QZiGf26FEWWLtG9PAnA9Jee3AZI9JMGwEpAeQDl0bfe4qz9U9YmiMlwwL0DxllzzEZgb xwaykfes0ayFUvw4w5Pd+oT5XS4smgNZdp1S0l3RsNHkAGgZ7UMRa1ScoTiQebIPkItZ GsOQ== Received: by 10.182.75.6 with SMTP id y6mr7194253obv.70.1348615149367; Tue, 25 Sep 2012 16:19:09 -0700 (PDT) Received: by 10.182.75.6 with SMTP id y6mr7194246obv.70.1348615149170; Tue, 25 Sep 2012 16:19:09 -0700 (PDT) Received: from coign.google.com ([2620:0:1000:5e02:224:d7ff:fe8f:f634]) by mx.google.com with ESMTPS id k8sm1201129oeh.9.2012.09.25.16.19.07 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 25 Sep 2012 16:19:08 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Better error for switch on non-comparable type Date: Tue, 25 Sep 2012 16:19:01 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlwkqkMdI2x2NrSyN6r5T0ym10hifpVv8hSfrxZIQqxLZII41S9FOC9MsBfXTp27H/9uorSCqte7YQ3mS5fLa8uTkDYQeNepr0V0FuYlhSaWZ39G/Kxvlo/y55R2VEYxUtpRwBtu7FqfiTkb3aYLWcIDosi0VBUd6x9LMcPJZLYsZkEGBDhVjJMA0rwm08GzWoRCXXg X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch to the Go frontend gives a better error message for a switch on a non-comparable type. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline and 4.7 branch. Ian diff -r 74d2d7d217d8 -r f47f5449a663 go/statements.cc --- a/go/statements.cc Sat Sep 22 00:17:10 2012 -0700 +++ b/go/statements.cc Mon Sep 24 15:20:45 2012 -0700 @@ -3846,6 +3846,16 @@ return new Constant_switch_statement(this->val_, this->clauses_, this->break_label_, loc); + if (this->val_ != NULL + && !this->val_->type()->is_comparable() + && !Type::are_compatible_for_comparison(true, this->val_->type(), + Type::make_nil_type(), NULL)) + { + error_at(this->val_->location(), + "cannot switch on value whose type that may not be compared"); + return Statement::make_error_statement(loc); + } + Block* b = new Block(enclosing, loc); if (this->clauses_->empty())