From patchwork Thu Dec 12 21:35:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 300764 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BB0582C00A2 for ; Fri, 13 Dec 2013 08:35:15 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=CLeqhxuBx7AL0FSLdVuqYTIC4eco0GL3xcZIj6OrYJbAWk9+szlTb g1xTiuM+LJR2FNWIkZ0MRGaZSEMLjakWbZ56XTrLe/8m0z9/YOr0c4MnEitNLQ5T 9Y+Q/tuX6FpPVkQBuDJhBtoCiafQbBAEpZyz+qxSVGmn9RQLLujpVU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=ykVguvxYSiw+BBtzM1VhONSo01I=; b=MCo15zXWdRTYgh0J81de uZUK5WIHT5b5ln//xsQYWTjQq/vZISMsqHb9X6vplZW3cWUe5htvMGeqaD0agLGn KDn62gtip+0WGkhRNMH047UOw+Ni0btYc7T8RQva/lyB1Gn47nNIp0N7natC2y1+ DoiL2FgCx396gcgHN07xbQA= Received: (qmail 28504 invoked by alias); 12 Dec 2013 21:35:09 -0000 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 Received: (qmail 28495 invoked by uid 89); 12 Dec 2013 21:35:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS, T_TVD_MIME_NO_HEADERS autolearn=ham version=3.3.2 X-HELO: mail-pb0-f51.google.com Received: from mail-pb0-f51.google.com (HELO mail-pb0-f51.google.com) (209.85.160.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 12 Dec 2013 21:35:07 +0000 Received: by mail-pb0-f51.google.com with SMTP id up15so1257409pbc.10 for ; Thu, 12 Dec 2013 13:35:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:user-agent :mime-version:content-type; bh=tcl5HM+pnSPM6yfzS8KzITJl6fEM9U6ePKjmChPnQAI=; b=JybHnywiIHnpW+SpTNPJncJ72Yr31bHENQkuw/o+tDmT5wNEd9ZpYSVg9Y+XrbckKC xE2W4FyfttqBoPZOM7JoJwSkXb3gDdC+4I05tXNPidhDip9wzfv/CAAczozP0tB4lcpF dXG1Zf9M5wJGMBdKF/9syh7S6j3Jn7NqcSxhwUYxUa8pX7iM6GGmyo8EkaTBwUvcJKMz smhl1Qx1kFnAOWDzPKyeoMmqG0KvxY1t2z6zder0L0xKWrh3Df4bi4+AQbyb8D2gZFx2 H6SaW6VDPwF3vAtnZldJvmRbIbx7Eh2yTCAYZ53cAEH/V9pbXxywublg3aLRm7i1f5H+ 7KyQ== X-Gm-Message-State: ALoCoQn+7XJP7miLQctZ76kBSgVdL0hQ2CyeFfaP2Wf2F5EooTznz1icAXcLu5Pq0J26/DqqjH0X5Q8FuxaXPIg2ixLGDUmtViPp91HiIgrP9gCOR/7Mj1IkMZLpkyMRb+23YBdYLvOAOQPmorRvqXqruY0PIvmcxf1IoRYFuHoyb/hxencld7ZhnYaPsL24smwJTqWYEZNmdceDTkZ+Xpjb/oUFf9mkCw== X-Received: by 10.68.242.163 with SMTP id wr3mr16150464pbc.84.1386884106169; Thu, 12 Dec 2013 13:35:06 -0800 (PST) Received: from iant-glaptop.roam.corp.google.com.google.com ([172.26.49.29]) by mx.google.com with ESMTPSA id fk4sm58583086pab.23.2013.12.12.13.35.04 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 12 Dec 2013 13:35:05 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Better error messages for { on next line Date: Thu, 12 Dec 2013 13:35:02 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes The Go language requires that the { starting a block for an if, for, or switch statement be on the same line as the if/for/switch. This patch gives better error messages when a program does it wrong. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r ee6b0181e864 go/parse.cc --- a/go/parse.cc Thu Dec 12 13:02:33 2013 -0800 +++ b/go/parse.cc Thu Dec 12 13:32:41 2013 -0800 @@ -4287,6 +4287,16 @@ cond = this->expression(PRECEDENCE_NORMAL, false, false, NULL, NULL); } + // Check for the easy error of a newline before starting the block. + if (this->peek_token()->is_op(OPERATOR_SEMICOLON)) + { + Location semi_loc = this->location(); + if (this->advance_token()->is_op(OPERATOR_LCURLY)) + error_at(semi_loc, "missing %<{%> after if clause"); + // Otherwise we will get an error when we call this->block + // below. + } + this->gogo_->start_block(this->location()); Location end_loc = this->block(); Block* then_block = this->gogo_->finish_block(end_loc); @@ -4431,7 +4441,7 @@ Location token_loc = this->location(); if (this->peek_token()->is_op(OPERATOR_SEMICOLON) && this->advance_token()->is_op(OPERATOR_LCURLY)) - error_at(token_loc, "unexpected semicolon or newline before %<{%>"); + error_at(token_loc, "missing %<{%> after switch clause"); else if (this->peek_token()->is_op(OPERATOR_COLONEQ)) { error_at(token_loc, "invalid variable name"); @@ -5158,6 +5168,16 @@ } } + // Check for the easy error of a newline before starting the block. + if (this->peek_token()->is_op(OPERATOR_SEMICOLON)) + { + Location semi_loc = this->location(); + if (this->advance_token()->is_op(OPERATOR_LCURLY)) + error_at(semi_loc, "missing %<{%> after for clause"); + // Otherwise we will get an error when we call this->block + // below. + } + // Build the For_statement and note that it is the current target // for break and continue statements. @@ -5224,8 +5244,7 @@ *cond = NULL; else if (this->peek_token()->is_op(OPERATOR_LCURLY)) { - error_at(this->location(), - "unexpected semicolon or newline before %<{%>"); + error_at(this->location(), "missing %<{%> after for clause"); *cond = NULL; *post = NULL; return;