From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Archive: List-Post: List-Help: Sender: gcc-patches-owner@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: Sat, 25 Jul 2015 07:32:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040901070803020701030404" X-SW-Source: 2015-07/txt/msg02149.txt.bz2 This is a multi-part message in MIME format. --------------040901070803020701030404 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 628 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. --------------040901070803020701030404 Content-Type: text/x-patch; name="64989.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="64989.patch" Content-length: 1805 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); --------------040901070803020701030404--