From patchwork Fri Oct 14 17:55:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 119879 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 1A217B6FD7 for ; Sat, 15 Oct 2011 04:56:25 +1100 (EST) Received: (qmail 7722 invoked by alias); 14 Oct 2011 17:56:20 -0000 Received: (qmail 7713 invoked by uid 22791); 14 Oct 2011 17:56:18 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 14 Oct 2011 17:55:56 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9EHttxY014280 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 14 Oct 2011 13:55:55 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p9EHtsPt014707 for ; Fri, 14 Oct 2011 13:55:54 -0400 Received: from [0.0.0.0] (ovpn-113-74.phx2.redhat.com [10.3.113.74]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p9EHtrCs018692 for ; Fri, 14 Oct 2011 13:55:54 -0400 Message-ID: <4E9877A8.7080003@redhat.com> Date: Fri, 14 Oct 2011 13:55:52 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20111001 Thunderbird/7.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/50563 (NSDMI and multiple declarator list) 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 The problem here was that we were saving away the second declarator as part of the NSDMI for the first declarator. Fixed by stopping at a non-nested comma. Tested x86_64-pc-linux-gnu, applying to trunk. commit 09f16be794e871607c2bb46bf74206ee40af1b74 Author: Jason Merrill Date: Thu Oct 13 17:51:13 2011 -0400 PR c++/50563 * parser.c (cp_parser_cache_group): Handle end==CPP_COMMA. (cp_parser_save_nsdmi): Pass it. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index cabe9aa..ea0c4dc 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -20617,7 +20617,8 @@ cp_parser_save_nsdmi (cp_parser* parser) cp_token *last; tree node; - cp_parser_cache_group (parser, CPP_CLOSE_PAREN, /*depth=*/0); + /* Save tokens until the next comma or semicolon. */ + cp_parser_cache_group (parser, CPP_COMMA, /*depth=*/0); last = parser->lexer->next_token; @@ -21719,6 +21720,12 @@ cp_parser_cache_group (cp_parser *parser, kind of syntax error. */ return true; + /* If we're caching something finished by a comma (or semicolon), + such as an NSDMI, don't consume the comma. */ + if (end == CPP_COMMA + && (token->type == CPP_SEMICOLON || token->type == CPP_COMMA)) + return false; + /* Consume the token. */ cp_lexer_consume_token (parser->lexer); /* See if it starts a new group. */ diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-list1.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-list1.C new file mode 100644 index 0000000..526f29a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-list1.C @@ -0,0 +1,14 @@ +// PR c++/50563 +// { dg-options -std=c++0x } + +struct S1 { + int a{10}, b{20}; // OK +}; + +struct S2 { + int a, b = 20; // OK +}; + +struct S3 { + int a = 10, b = 20; +};