From patchwork Sat Jul 6 00:47:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 257222 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 7A2502C009D for ; Sat, 6 Jul 2013 10:48:14 +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=vP4VHJ9ZeVzdAQjZE6XaR7X4SceSSOM1h+1yt5CgNcx zkryAmcvuiMJNsWJiH5xh11yxkF/N3g9lShhXhjO3BxEdp/0kZRvWbYZFwP/DvID s/GUay8pOx9Kyw8n44fidxyzQdNAppc+ZVWDFYisIgRw06ud6I8rekQQf4mpKesg = 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=+ylyZTNuBCBSFqc1RTPAvvDHuT8=; b=vx0EynHCu9c/pv3TI 0p2XrLz9LEhLbJA1zo5Cy+axhCmb4eJpuRdhY1tkoyMYrif2HIMMGpmYNjEBncfE cBWGHqsXoGjCizcUOQ7F7L5nGNDm0Jq1UsJCni1CF83jbaAKb0ALANkyK8ksOYMR KA+m7nisZDqZzGowsFb8T+RT2w= Received: (qmail 7956 invoked by alias); 6 Jul 2013 00:48:08 -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 7933 invoked by uid 89); 6 Jul 2013 00:48:02 -0000 X-Spam-SWARE-Status: No, score=-5.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_W, 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, 06 Jul 2013 00:48:01 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r660lwNn017110 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 6 Jul 2013 00:47:59 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r660lvN2014096 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 6 Jul 2013 00:47:58 GMT Received: from abhmt116.oracle.com (abhmt116.oracle.com [141.146.116.68]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r660lvjD013138; Sat, 6 Jul 2013 00:47:57 GMT Received: from poldo4.casa (/79.47.195.146) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 05 Jul 2013 17:47:57 -0700 Message-ID: <51D76937.1060807@oracle.com> Date: Sat, 06 Jul 2013 02:47:51 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 28262 X-Virus-Found: No Hi, this old issue is about default arguments not rejected for function typedefs. We have got infrastructure for that - parser->default_arg_ok_p - and it seems to me that we can safely set the flag to false in cp_parser_init_declarator when the decl_specifier has ds_typedef set. Tested x86_64-linux. Thanks, Paolo. //////////////////////// /cp 2013-07-05 Paolo Carlini PR c++/28262 * parser.c (cp_parser_init_declarator): If we are parsing a typedef set parser->default_arg_ok_p to false before cp_parser_declarator. /testsuite 2013-07-05 Paolo Carlini PR c++/28262 * g++.dg/parse/defarg16.C: New. Index: cp/parser.c =================================================================== --- cp/parser.c (revision 200725) +++ cp/parser.c (working copy) @@ -16182,6 +16182,7 @@ cp_parser_init_declarator (cp_parser* parser, bool friend_p; tree pushed_scope = NULL_TREE; bool range_for_decl_p = false; + bool saved_default_arg_ok_p = parser->default_arg_ok_p; /* Gather the attributes that were provided with the decl-specifiers. */ @@ -16192,6 +16193,10 @@ cp_parser_init_declarator (cp_parser* parser, if (function_definition_p) *function_definition_p = false; + /* Default arguments are only permitted for function parameters. */ + if (decl_spec_seq_has_spec_p (decl_specifiers, ds_typedef)) + parser->default_arg_ok_p = false; + /* Defer access checks while parsing the declarator; we cannot know what names are accessible until we know what is being declared. */ @@ -16207,6 +16212,8 @@ cp_parser_init_declarator (cp_parser* parser, /* Gather up the deferred checks. */ stop_deferring_access_checks (); + parser->default_arg_ok_p = saved_default_arg_ok_p; + /* If the DECLARATOR was erroneous, there's no need to go further. */ if (declarator == cp_error_declarator) Index: testsuite/g++.dg/parse/defarg16.C =================================================================== --- testsuite/g++.dg/parse/defarg16.C (revision 0) +++ testsuite/g++.dg/parse/defarg16.C (working copy) @@ -0,0 +1,4 @@ +// PR c++/28262 + +typedef void (funcptrhack) (int = 10); // { dg-error "default arguments" } +typedef funcptrhack * funcptr;