From patchwork Sat May 18 02:14:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 244722 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 9AB882C009B for ; Sat, 18 May 2013 12:14:31 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=PsE1FW5LOcf64hEjC6RSiAKNbr5Y9CCFBD+HAQJTAT5 BqdWxh0W/MVKFWLxxfGcDuOPAldrLsFrtEOtZcMeZic2c/5DKBSotS96w0LgSUDF vaHJ2Q6P3Eojy0ttgfCTU5pm6QftBndwMME8Aj3ZyqZpm5thJA+29ImScJBtuSy0 = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=VwCjm2vO9wQFRlwQhFfOj5BIvSY=; b=WeS2sjUeK7UsjDx8g 6oAFhqe9ZGCBi1VEvzMl7N+t9Yx3zTZE02N78XIYCQ9PJnDPv1mTsTol+Dt+i6OG qgcp56EwV/9StY53eli85rHR9AsaDZNqNzCHe/UVWiS2ZQmcqdUiym+SgyOhyq02 tT8IJsxF1cKCIflPm0ebvfUMDM= Received: (qmail 18002 invoked by alias); 18 May 2013 02:14:24 -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 17978 invoked by uid 89); 18 May 2013 02:14:20 -0000 X-Spam-SWARE-Status: No, score=-5.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sat, 18 May 2013 02:14:19 +0000 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r4I2EHRQ017984 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 18 May 2013 02:14:17 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r4I2EFLW021688 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Sat, 18 May 2013 02:14:16 GMT Received: from abhmt118.oracle.com (abhmt118.oracle.com [141.146.116.70]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r4I2EFSw028587; Sat, 18 May 2013 02:14:15 GMT Received: from poldo4.casa (/79.52.195.242) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 17 May 2013 19:14:15 -0700 Message-ID: <5196E3F4.5050707@oracle.com> Date: Sat, 18 May 2013 04:14:12 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 10207 X-Virus-Found: No Hi, in this even older ;) and related issue, we reject empty initializer lists in compound-literals. The fix seems simple: just use cp_parser_braced_list instead of cp_parser_initializer_list, which allows for the special case of empty list. Tested x86_64-linux. There is a nit which I don't want to hide: cp_parser_initializer_list + build_constructor does a little more than cp_parser_braced_list: in build_constructor there is a loop setting TREE_SIDE_EFFECTS and TREE_CONSTANT to the right value for the CONSTRUCTOR overall, which doesn't exist in cp_parser_braced_list. In case it matters - I don't think it does, and we have testcases with side effects in the testsuite - we can't simply add it to cp_parser_braced_list, because its many existing uses are perfectly fine without. A little more code would be needed, not a big issue. Thanks, Paolo. /////////////////////// /cp 2013-05-18 Paolo Carlini PR c++/10207 * parser.c (cp_parser_postfix_expression): Use cp_parser_braced_list instead of cp_parser_initializer_list for compound-literals. /testsuite 2013-05-18 Paolo Carlini PR c++/10207 * g++.dg/ext/complit13.C: New. Index: cp/parser.c =================================================================== --- cp/parser.c (revision 199043) +++ cp/parser.c (working copy) @@ -5719,7 +5719,7 @@ cp_parser_postfix_expression (cp_parser *parser, b if (cp_parser_allow_gnu_extensions_p (parser) && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN)) { - vec *initializer_list = NULL; + tree initializer = NULL_TREE; bool saved_in_type_id_in_expr_p; cp_parser_parse_tentatively (parser); @@ -5732,21 +5732,19 @@ cp_parser_postfix_expression (cp_parser *parser, b parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p; /* Look for the `)'. */ cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN); - /* Look for the `{'. */ - cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE); /* If things aren't going well, there's no need to keep going. */ if (!cp_parser_error_occurred (parser)) { - bool non_constant_p; - /* Parse the initializer-list. */ - initializer_list - = cp_parser_initializer_list (parser, &non_constant_p); - /* Allow a trailing `,'. */ - if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)) - cp_lexer_consume_token (parser->lexer); - /* Look for the final `}'. */ - cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE); + if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE)) + { + bool non_constant_p; + /* Parse the brace-enclosed initializer list. */ + initializer = cp_parser_braced_list (parser, + &non_constant_p); + } + else + cp_parser_simulate_error (parser); } /* If that worked, we're definitely looking at a compound-literal expression. */ @@ -5754,7 +5752,8 @@ cp_parser_postfix_expression (cp_parser *parser, b { /* Warn the user that a compound literal is not allowed in standard C++. */ - pedwarn (input_location, OPT_Wpedantic, "ISO C++ forbids compound-literals"); + pedwarn (input_location, OPT_Wpedantic, + "ISO C++ forbids compound-literals"); /* For simplicity, we disallow compound literals in constant-expressions. We could allow compound literals of integer type, whose @@ -5772,10 +5771,8 @@ cp_parser_postfix_expression (cp_parser *parser, b } /* Form the representation of the compound-literal. */ postfix_expression - = (finish_compound_literal - (type, build_constructor (init_list_type_node, - initializer_list), - tf_warning_or_error)); + = (finish_compound_literal (type, initializer, + tf_warning_or_error)); break; } } Index: testsuite/g++.dg/ext/complit13.C =================================================================== --- testsuite/g++.dg/ext/complit13.C (revision 0) +++ testsuite/g++.dg/ext/complit13.C (working copy) @@ -0,0 +1,11 @@ +// PR c++/10207 +// { dg-options "" } + +typedef struct { } EmptyStruct; +typedef struct { EmptyStruct Empty; } DemoStruct; + +void Func() +{ + DemoStruct Demo; + Demo.Empty = (EmptyStruct) {}; +}