From patchwork Mon Dec 5 15:35:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 129335 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 91FF61007D4 for ; Tue, 6 Dec 2011 02:37:11 +1100 (EST) Received: (qmail 20119 invoked by alias); 5 Dec 2011 15:37:07 -0000 Received: (qmail 20003 invoked by uid 22791); 5 Dec 2011 15:37:06 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rcsinet15.oracle.com (HELO rcsinet15.oracle.com) (148.87.113.117) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 05 Dec 2011 15:36:53 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by rcsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id pB5FapI2002831 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 5 Dec 2011 15:36:52 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id pB5FaoSb004099 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 5 Dec 2011 15:36:51 GMT Received: from abhmt116.oracle.com (abhmt116.oracle.com [141.146.116.68]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id pB5Fajlb023898 for ; Mon, 5 Dec 2011 09:36:45 -0600 Received: from [192.168.1.4] (/79.52.234.206) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 05 Dec 2011 07:36:45 -0800 Message-ID: <4EDCE4D3.3090800@oracle.com> Date: Mon, 05 Dec 2011 16:35:47 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: gcc-patches@gcc.gnu.org Subject: Re: [C++ Patch] PR 51404 References: <4EDBB331.2030208@oracle.com> <4EDCDC8C.1000802@redhat.com> In-Reply-To: <4EDCDC8C.1000802@redhat.com> 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 Hi, > Hmm, I think giving the additional error was intentional, which is why > we check for error_operand_p after giving it. But I suppose I'm not > attached to that. > > We could avoid reformatting by adding > > if (error_operand_p (bounds)) > /* Already gave an error. */; > > OK either way. Thanks. Thus I'm going to apply the below. By the way, something I didn't like about the simpler patch not tweaking cp_parser_direct_declarator is that we would handle inconsistently the two tests in auto25.C, producing the more verbose diagnostic only for the first one. A little more work would be needed. Paolo. /cp 2011-12-05 Paolo Carlini PR c++/51404 * typeck2.c (build_functional_cast): Early return error_mark_node for invalid uses of 'auto'. * parser.c (cp_parser_direct_declarator): When cp_parser_constant_expression returns error do not produce further diagnostic for the bound. /testsuite 2011-12-05 Paolo Carlini PR c++/51404 * g++.dg/cpp0x/auto28.C: New. Index: testsuite/g++.dg/cpp0x/auto28.C =================================================================== --- testsuite/g++.dg/cpp0x/auto28.C (revision 0) +++ testsuite/g++.dg/cpp0x/auto28.C (revision 0) @@ -0,0 +1,4 @@ +// PR c++/51404 +// { dg-options -std=c++0x } + +int i = auto().x; // { dg-error "invalid use of" } Index: cp/typeck2.c =================================================================== --- cp/typeck2.c (revision 182007) +++ cp/typeck2.c (working copy) @@ -1653,7 +1653,7 @@ build_functional_cast (tree exp, tree parms, tsubs { if (complain & tf_error) error ("invalid use of %"); - type = error_mark_node; + return error_mark_node; } if (processing_template_decl) Index: cp/parser.c =================================================================== --- cp/parser.c (revision 182007) +++ cp/parser.c (working copy) @@ -16055,18 +16055,20 @@ cp_parser_direct_declarator (cp_parser* parser, &non_constant_p); if (!non_constant_p) /* OK */; - /* Normally, the array bound must be an integral constant - expression. However, as an extension, we allow VLAs - in function scopes as long as they aren't part of a - parameter declaration. */ + else if (error_operand_p (bounds)) + /* Already gave an error. */; else if (!parser->in_function_body || current_binding_level->kind == sk_function_parms) { + /* Normally, the array bound must be an integral constant + expression. However, as an extension, we allow VLAs + in function scopes as long as they aren't part of a + parameter declaration. */ cp_parser_error (parser, "array bound is not an integer constant"); bounds = error_mark_node; } - else if (processing_template_decl && !error_operand_p (bounds)) + else if (processing_template_decl) { /* Remember this wasn't a constant-expression. */ bounds = build_nop (TREE_TYPE (bounds), bounds);