From patchwork Thu Feb 7 17:41:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 218972 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 80B062C0091 for ; Fri, 8 Feb 2013 04:42:21 +1100 (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=1360863742; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=Myk2ylR+GeAEEvTFSqwa 3CLqzvw=; b=OIT/FM88sOjyG/gFqlfIrMUPGeCf3QyNoOhelx9CrpVOC2Yrz7+A vfiTftIO7i00Yv8W5xCgz0+4S3cYkKy6I0DqM/BiQPiXBARqb3xTqVsw7MM9NN0S Hri7uytUBuO0R/e41uAe1YH4LwIGoubr/hDTrR6s0n2ac+sYxG+svxk= 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:Date:From:To:Cc:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Z+jc9pcCtvObbKGD4gvZqQjtHeZCl4dVdnldfxqA4KBAnUE7a7VJr+YHhsiSea jsRWIo8zfbFaIGk/YINWMQhZF457wNW9neylj0HySWFhmt4mDfQ8kboWE7bNBkxL lIMol7KukgO3aXdTu9ZCYH3KGHXvsaf8EqIhyUMMKlGXw=; Received: (qmail 4790 invoked by alias); 7 Feb 2013 17:42:03 -0000 Received: (qmail 4707 invoked by uid 22791); 7 Feb 2013 17:42:01 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, 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; Thu, 07 Feb 2013 17:41:54 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r17HfrZJ013416 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 7 Feb 2013 12:41:53 -0500 Received: from zalov.redhat.com (vpn1-5-55.ams2.redhat.com [10.36.5.55]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r17HfpK5010338 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 7 Feb 2013 12:41:52 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id r17Hfpeb008361; Thu, 7 Feb 2013 18:41:51 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r17Hfo9a008360; Thu, 7 Feb 2013 18:41:50 +0100 Date: Thu, 7 Feb 2013 18:41:50 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [committed] Fix parsing of ((type ()) () (PR c++/56239) Message-ID: <20130207174150.GH4385@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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! As discussed in the PR, () isn't valid unary expression, so ((type ()) () needs to be parsed as a function call instead. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, approved by Jason in the PR, committed to trunk. 2013-02-07 Jakub Jelinek PR c++/56239 * parser.c (cp_parser_token_starts_cast_expression): Renamed to... (cp_parser_tokens_start_cast_expression): ... this. Change parameter to cp_parser *, call cp_lexer_peek_token first. For CPP_OPEN_PAREN, return true only if 2nd token isn't CPP_CLOSE_PAREN. (cp_parser_cast_expression): Adjust caller. * g++.dg/parse/pr56239.C: New test. Jakub --- gcc/cp/parser.c.jj 2013-02-07 08:59:50.000000000 +0100 +++ gcc/cp/parser.c 2013-02-07 13:53:16.169450209 +0100 @@ -7091,8 +7091,9 @@ cp_parser_delete_expression (cp_parser* otherwise. */ static bool -cp_parser_token_starts_cast_expression (cp_token *token) +cp_parser_tokens_start_cast_expression (cp_parser *parser) { + cp_token *token = cp_lexer_peek_token (parser->lexer); switch (token->type) { case CPP_COMMA: @@ -7133,6 +7134,12 @@ cp_parser_token_starts_cast_expression ( case CPP_EOF: return false; + case CPP_OPEN_PAREN: + /* In ((type ()) () the last () isn't a valid cast-expression, + so the whole must be parsed as postfix-expression. */ + return cp_lexer_peek_nth_token (parser->lexer, 2)->type + != CPP_CLOSE_PAREN; + /* '[' may start a primary-expression in obj-c++. */ case CPP_OPEN_SQUARE: return c_dialect_objc (); @@ -7225,8 +7232,7 @@ cp_parser_cast_expression (cp_parser *pa parenthesized ctor such as `(T ())' that looks like a cast to function returning T. */ if (!cp_parser_error_occurred (parser) - && cp_parser_token_starts_cast_expression (cp_lexer_peek_token - (parser->lexer))) + && cp_parser_tokens_start_cast_expression (parser)) { cp_parser_parse_definitely (parser); expr = cp_parser_cast_expression (parser, --- gcc/testsuite/g++.dg/parse/pr56239.C.jj 2013-02-07 13:56:04.628448688 +0100 +++ gcc/testsuite/g++.dg/parse/pr56239.C 2013-02-07 13:55:14.000000000 +0100 @@ -0,0 +1,13 @@ +// PR c++/56239 +// { dg-do compile } + +struct S +{ + int operator () () { return 0; } +}; + +int +main () +{ + return (S ()) (); +}