From patchwork Mon May 21 13:47:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 160362 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 E6007B6F6E for ; Mon, 21 May 2012 23:49:47 +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=1338212988; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Message-ID:Date:From:User-Agent:MIME-Version: To:CC:Subject:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=hJ63/KqEN9cUmPltvhkExZGZowQ=; b=dq6t+5LByxG6787 vuiM1iSsg9nNX4QRjeR/X/akF5+nBv06l6fHgu2KcFXdLEhPRQFdZf48BD/sDouY mqWT0e008y55CtzUJKJB+hjUZTg1DnKdtjGW9I9y3iIVKWOczxJn1nfzuisp6wXR XyimpEmfZ+qWKtBMVuG3+CvON5Og= 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:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=cG/ROOjfrsJKEiPA5ZMFS8FGsXg4iyHf6nFbXryQADlCIPvRL2jo5qnT31qD2S 8OgmI/5A06knVyFv5dQSwMbhbHlR3EXj1Ozn5+mMsTQ2SPHmGetO7DO+qexhRl3v vfPVt/dKt3D1tiVpOeRJ1gk/0mEVYw0+y3C1Y++XuvnLY=; Received: (qmail 19255 invoked by alias); 21 May 2012 13:49:08 -0000 Received: (qmail 19047 invoked by uid 22791); 21 May 2012 13:49:02 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_W, T_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, 21 May 2012 13:48:48 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by rcsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q4LDmlVt007397 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 21 May 2012 13:48:47 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 q4LDmkLf019790 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 21 May 2012 13:48:47 GMT Received: from abhmt107.oracle.com (abhmt107.oracle.com [141.146.116.59]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q4LDmkGb023915; Mon, 21 May 2012 08:48:46 -0500 Received: from [192.168.1.4] (/79.43.213.121) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 21 May 2012 06:48:46 -0700 Message-ID: <4FBA477E.5050609@oracle.com> Date: Mon, 21 May 2012 15:47:42 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120421 Thunderbird/12.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 40821 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, this is a rather old diagnostic issue, already reported at least 3 times, recently too. I tried various small variants of the same idea, and the below appears to work well enough: it tells the user about all the missing open and closed parentheses and overall the diagnostic is quite similar in terms of quality and quantity to what EDG produces, for example. Booted and tested x86_64-linux. Thanks, Paolo. //////////////////////// /cp 2012-05-21 Paolo Carlini PR c++/40821 * parser.c (cp_parser_attributes_opt): Enforce error checking of unbalanced parentheses in the presence of tentative parsing. /testsuite 2012-05-21 Paolo Carlini PR c++/40821 * g++.dg/ext/attrib46.C: New. Index: testsuite/g++.dg/ext/attrib46.C =================================================================== --- testsuite/g++.dg/ext/attrib46.C (revision 0) +++ testsuite/g++.dg/ext/attrib46.C (revision 0) @@ -0,0 +1,4 @@ +// PR c++/40821 + +struct __attribute__((aligned(8)) S1 { int i; }; // { dg-error "expected" } +struct __attribute__( aligned(8) S2 { int i; }; // { dg-error "expected" } Index: cp/parser.c =================================================================== --- cp/parser.c (revision 187704) +++ cp/parser.c (working copy) @@ -20052,6 +20052,7 @@ cp_parser_attributes_opt (cp_parser* parser) { cp_token *token; tree attribute_list; + bool ok = true; /* Peek at the next token. */ token = cp_lexer_peek_token (parser->lexer); @@ -20076,8 +20077,12 @@ cp_parser_attributes_opt (cp_parser* parser) attribute_list = NULL; /* Look for the two `)' tokens. */ - cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN); - cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN); + if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN)) + ok = false; + if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN)) + ok = false; + if (!ok) + cp_parser_skip_to_end_of_statement (parser); /* Add these new attributes to the list. */ attributes = chainon (attributes, attribute_list);