From patchwork Tue Jan 26 16:31:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 573355 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45FB914029E for ; Wed, 27 Jan 2016 03:32:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=E/QlKFgT; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=A17tKFQGJ/X9 x6hdOEV2jmUiEdkc5rq30IKpooHd+MCokDihNBYxC0k/cKd7FqegCy4KPFapZ9gN L7HYUoljRMmOcKRa7roZNcmKnG+hh2DZP8yRFgvIv6WmRu0sOAPbtGHXManlHe5A X0IbjjeUaI/+CcZfrjsgRAxMKPsZmM4= 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:from :to:cc:subject:date:message-id; s=default; bh=qjnZLQQ49W5AsUStgs J1aI7RI3w=; b=E/QlKFgTmuUT5Grxi35SaFzJCg2yc/dip3S5mFr20i0UC8H4aC AiIlpiOXJempv1xpaJ2RRcOGC3OPLBmOHPCnAwWzdtGWjR76S3PSIp25KYI3AeEU dvMzfTbsuhs/clmgoUazcawj4lDmF+odCLSNRDYBjHvLSuGRTg+MTIZWM= Received: (qmail 78319 invoked by alias); 26 Jan 2016 16:31:55 -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 78305 invoked by uid 89); 26 Jan 2016 16:31:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=late X-HELO: mail-qg0-f51.google.com Received: from mail-qg0-f51.google.com (HELO mail-qg0-f51.google.com) (209.85.192.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 26 Jan 2016 16:31:53 +0000 Received: by mail-qg0-f51.google.com with SMTP id b35so142585124qge.0 for ; Tue, 26 Jan 2016 08:31:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=OD7KM8f/zKVleSunWVbSDtf32qAtEbFyfj5TcBksdT8=; b=BpVGueaAZ60/PPlpHMQR2Syv6xq8WsGD3uebJ1IE5nZjWc/glvSxjV7OXh2WMK/E4j qjPK+UoPU3Z0Ciq3ql7yP92UZu0ld7j7kvZaWyIgPlL+uGl7m820XtgjpKJP+RSzyTRF E6dyaQL+HBi+kq3RxCNfKSgfza9Ai4I+WC9DEmDHPivyR7PlhBJE1VTdW6phfbw2QQYV /GKDxjzX2DsuigNP0l+0LMt8kYnfWWNgmPH+rpw6qTtD9L+4Ov1DTaGrsifZvJmzBJGD SDftZoVizUgXbfQA+lM2Sb4YQ2ASPNGtH6jIMMlS62A4UgH95lFyTreS/ZVF7AyToVL+ pFMQ== X-Gm-Message-State: AG10YOQCuCrQuBYSo/coSFCB9lpm+U+ztiNcTtQIhVeZUp3clOJzDph1X/VQh9V3FRY6XQ== X-Received: by 10.140.109.247 with SMTP id l110mr29139244qgf.52.1453825911620; Tue, 26 Jan 2016 08:31:51 -0800 (PST) Received: from localhost.localdomain (ool-4353abbc.dyn.optonline.net. [67.83.171.188]) by smtp.gmail.com with ESMTPSA id a130sm798394qhd.9.2016.01.26.08.31.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Jan 2016 08:31:50 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] Fix PR c++/69139 (deduction failure with trailing return type) Date: Tue, 26 Jan 2016 11:31:26 -0500 Message-Id: <1453825886-27672-1-git-send-email-patrick@parcs.ath.cx> This patch makes the parser more robust in determining whether an 'auto' specifier that appears in a parameter declaration corresponds to a placeholder for a late return type, or corresponds to an implicit template parameter as for an abbreviated function template. Bootstrap + regtest in progress on x86_64-pc-linux-gnu, will also test this change against Boost. OK to commit if testing succeeds? What about for GCC 4.9/5? gcc/cp/ChangeLog: PR c++/69139 * parser.c (cp_parser_simple_type_specifier): Make the check for disambiguating between an 'auto' placeholder and an implicit template parameter more robust. gcc/testsuite/ChangeLog: PR c++/69139 * g++.dg/cpp0x/auto47.C: New test. --- gcc/cp/parser.c | 33 +++++++++++++++++++++++---------- gcc/testsuite/g++.dg/cpp0x/auto47.C | 20 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/auto47.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index d03b0c9..56c834f 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -16032,20 +16032,33 @@ cp_parser_simple_type_specifier (cp_parser* parser, /* The 'auto' might be the placeholder return type for a function decl with trailing return type. */ bool have_trailing_return_fn_decl = false; - if (cp_lexer_peek_nth_token (parser->lexer, 2)->type - == CPP_OPEN_PAREN) + + cp_parser_parse_tentatively (parser); + cp_lexer_consume_token (parser->lexer); + while (cp_lexer_next_token_is_not (parser->lexer, CPP_EQ) + && cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA) + && cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN) + && cp_lexer_next_token_is_not (parser->lexer, CPP_EOF)) { - cp_parser_parse_tentatively (parser); - cp_lexer_consume_token (parser->lexer); - cp_lexer_consume_token (parser->lexer); - if (cp_parser_skip_to_closing_parenthesis (parser, + if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN)) + { + cp_lexer_consume_token (parser->lexer); + cp_parser_skip_to_closing_parenthesis (parser, /*recovering*/false, /*or_comma*/false, - /*consume_paren*/true)) - have_trailing_return_fn_decl - = cp_lexer_next_token_is (parser->lexer, CPP_DEREF); - cp_parser_abort_tentative_parse (parser); + /*consume_paren*/true); + continue; + } + + if (cp_lexer_next_token_is (parser->lexer, CPP_DEREF)) + { + have_trailing_return_fn_decl = true; + break; + } + + cp_lexer_consume_token (parser->lexer); } + cp_parser_abort_tentative_parse (parser); if (have_trailing_return_fn_decl) { diff --git a/gcc/testsuite/g++.dg/cpp0x/auto47.C b/gcc/testsuite/g++.dg/cpp0x/auto47.C new file mode 100644 index 0000000..08adf31 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/auto47.C @@ -0,0 +1,20 @@ +// PR c++/69139 +// { dg-do compile { target c++11 } } + +auto get(int) -> int { return {}; } +template int f(auto (*)(int) -> R) { return {}; } +int i = f(get); + +int foo1 (auto (int) -> char); + +int foo2 (auto f(int) -> char); + +int foo2 (auto (f)(int) -> char); + +int foo3 (auto (*f)(int) -> char); + +int foo4 (auto (*const **&f)(int) -> char); + +int foo5 (auto (*const **&f)(int, int *) -> char); + +int foo6 (auto (int) const -> char); // { dg-error "const" }