From patchwork Sat Jul 25 06:54:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 499908 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 0411C1402E2 for ; Sat, 25 Jul 2015 16:54:24 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Uqe9RoCw; 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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=JAn+vOlvgOZrjIq8gxQkJ8yl05akpzPyT0dNj2UjoY/tUOe8EO 7NOnwx7EROTmps5WABelIZna2W+/cxXAjVkpdlN19oby03VOW2i4zew0SYA/eMtI TgvEsnv4t2KJ4XnM+yqAtt/cXhqGMCrJBQyW+fRQiFmUvDIbcB+DJ9cOU= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=7lbs/+Ok3v0j2SJEJ9eU1FiZlDo=; b=Uqe9RoCwSfGtik7VrZPP XPVN1VJyt3aQ/6PnA+EXJKBhyXABZh9cUzSpSjvUclHLvUMtyVgjXKX2ajnguDSS LI1akh/pW/1qiYXL+N2aWHS3KlJrJ7yraT1RXte1qU88bYZKScePw7tNN07TGvRG fwSTGik12mCaG0pxzMN82ho= Received: (qmail 77146 invoked by alias); 25 Jul 2015 06:54:18 -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 77136 invoked by uid 89); 25 Jul 2015 06:54:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sat, 25 Jul 2015 06:54:16 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 04905388873 for ; Sat, 25 Jul 2015 06:54:14 +0000 (UTC) Received: from [10.10.116.39] ([10.10.116.39]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6P6sDuH013793 for ; Sat, 25 Jul 2015 02:54:14 -0400 To: gcc-patches List From: Jason Merrill Subject: C++ PATCH for c++/64989 (return type deduction with abbreviated function template) Message-ID: <55B33291.80605@redhat.com> Date: Fri, 24 Jul 2015 23:54:09 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In this testcase, the problem is that when we make_auto for the auto return type, we don't know yet that we're dealing with a function template, so the auto return type ends up with the same template parameter level as the implicit template parameters. This patch fixes this by generating a new auto at the correct level in splice_late_return_type, after we know that we're in a template. While I was messing with that function, I also tore out all the code for dealing with return types more complicated than plain 'auto', since the committee decided not to allow that. Tested x86_64-pc-linux-gnu, applying to trunk. commit ee4c93dbe9a300bb518f26dbd845de1ec8d1e1f2 Author: Jason Merrill Date: Fri Jul 24 22:58:39 2015 -0700 PR c++/64989 * pt.c (splice_late_return_type): Correct deduced return type for abbreviated function template. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 5004883..971c98e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -22459,15 +22459,19 @@ do_auto_deduction (tree type, tree init, tree auto_node) tree splice_late_return_type (tree type, tree late_return_type) { - tree argvec; + if (is_auto (type)) + { + if (late_return_type) + return late_return_type; - if (late_return_type == NULL_TREE) - return type; - argvec = make_tree_vec (1); - TREE_VEC_ELT (argvec, 0) = late_return_type; - if (current_template_parms) - argvec = add_to_template_args (current_template_args (), argvec); - return tsubst (type, argvec, tf_warning_or_error, NULL_TREE); + tree idx = get_template_parm_index (type); + if (TEMPLATE_PARM_LEVEL (idx) <= processing_template_decl) + /* In an abbreviated function template we didn't know we were dealing + with a function template when we saw the auto return type, so update + it to have the correct level. */ + return make_auto_1 (TYPE_IDENTIFIER (type)); + } + return type; } /* Returns true iff TYPE is a TEMPLATE_TYPE_PARM representing 'auto' or diff --git a/gcc/testsuite/g++.dg/cpp1z/abbrev1.C b/gcc/testsuite/g++.dg/cpp1z/abbrev1.C new file mode 100644 index 0000000..68a0bf3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/abbrev1.C @@ -0,0 +1,11 @@ +// PR c++/64969 +// { dg-options "-std=c++1z" } + +auto f1(auto x) { return *x; } +decltype(auto) f2(auto x) { return *x; } +auto f3(auto x) -> int { return *x; } + +int i; +auto r1 = f1(&i); +auto r2 = f2(&i); +auto r3 = f3(&i);