From patchwork Fri Feb 21 13:49:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 322867 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 69C882C020F for ; Sat, 22 Feb 2014 00:49:48 +1100 (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:subject:content-type; q= dns; s=default; b=dlCEvztfrGnDXb6uBMTbSKNLdvz8PgFoFDkv+fl1tJCnc2 0AhxhiGntc3V6DXaGaAZkPahFd9BZZuMluMVA3JJ9hbpUDhFPhhkvLz/cK2WmWVp Ot8X34nFAZWLLskBvLV+0KAHZC9/WBio97/6sXCUStro/76TgTQkNY1dmtaV8= 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:subject:content-type; s= default; bh=UJGBwhTm4qyRQo4H5qVR6c/Vi6k=; b=NCMeBortTdxyzd8bVRs+ mMDrXvxyflSZR3Zcm8DBfAjGen921zHmEm36xcNG75LiQJki4FPDdbY3tcvrQ9aR kmLwEK2WvTi3A8BXzf5z4L9xgm2r064/zAayklRepbrsyhaTf+WMDH4bsOJdM1+p qK0SiJ4bkRhfcJo1ke3N3+o= Received: (qmail 29456 invoked by alias); 21 Feb 2014 13:49:42 -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 29443 invoked by uid 89); 21 Feb 2014 13:49:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_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 ESMTP; Fri, 21 Feb 2014 13:49:39 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1LDncdK009292 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Feb 2014 08:49:38 -0500 Received: from [10.10.116.20] ([10.10.116.20]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s1LDnbYn015630 for ; Fri, 21 Feb 2014 08:49:37 -0500 Message-ID: <53075970.9090808@redhat.com> Date: Fri, 21 Feb 2014 08:49:36 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/60167 (reference template parameters) My patch for 58606 was incomplete; there were other places that needed to change to handle dereferencing reference non-type template parameters. Tested x86_64-pc-linux-gnu, applying to trunk. I reverted the earlier 58606 patch on the 4.8 branch. commit 7b1bb4515ae768ca44e192442d2578ea46c16f96 Author: Jason Merrill Date: Thu Feb 20 23:22:21 2014 -0500 PR c++/60167 PR c++/60222 PR c++/58606 * parser.c (cp_parser_template_argument): Restore dereference. * pt.c (template_parm_to_arg): Dereference non-pack expansions too. (process_partial_specialization): Handle deref. (unify): Likewise. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 4673f78..d8ccd2b 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -13937,6 +13937,7 @@ cp_parser_template_argument (cp_parser* parser) if (INDIRECT_REF_P (argument)) { + /* Strip the dereference temporarily. */ gcc_assert (REFERENCE_REF_P (argument)); argument = TREE_OPERAND (argument, 0); } @@ -13975,6 +13976,8 @@ cp_parser_template_argument (cp_parser* parser) if (address_p) argument = build_x_unary_op (loc, ADDR_EXPR, argument, tf_warning_or_error); + else + argument = convert_from_reference (argument); return argument; } } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 6477fce..4cf387a 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -3861,6 +3861,8 @@ template_parm_to_arg (tree t) SET_ARGUMENT_PACK_ARGS (t, vec); TREE_TYPE (t) = type; } + else + t = convert_from_reference (t); } return t; } @@ -4218,10 +4220,12 @@ process_partial_specialization (tree decl) if (/* These first two lines are the `non-type' bit. */ !TYPE_P (arg) && TREE_CODE (arg) != TEMPLATE_DECL - /* This next line is the `argument expression is not just a + /* This next two lines are the `argument expression is not just a simple identifier' condition and also the `specialized non-type argument' bit. */ - && TREE_CODE (arg) != TEMPLATE_PARM_INDEX) + && TREE_CODE (arg) != TEMPLATE_PARM_INDEX + && !(REFERENCE_REF_P (arg) + && TREE_CODE (TREE_OPERAND (arg, 0)) == TEMPLATE_PARM_INDEX)) { if ((!packed_args && tpd.arg_uses_template_parms[i]) || (packed_args && uses_template_parms (arg))) @@ -17893,6 +17897,12 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, /* Unification fails if we hit an error node. */ return unify_invalid (explain_p); + case INDIRECT_REF: + if (REFERENCE_REF_P (parm)) + return unify (tparms, targs, TREE_OPERAND (parm, 0), arg, + strict, explain_p); + /* FALLTHRU */ + default: /* An unresolved overload is a nondeduced context. */ if (is_overloaded_fn (parm) || type_unknown_p (parm)) diff --git a/gcc/testsuite/g++.dg/template/ref7.C b/gcc/testsuite/g++.dg/template/ref7.C new file mode 100644 index 0000000..f6395e2 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ref7.C @@ -0,0 +1,10 @@ +// PR c++/60167 + +template +struct Foo { + typedef int Bar; + + static Bar cache; +}; + +template typename Foo::Bar Foo::cache; diff --git a/gcc/testsuite/g++.dg/template/ref8.C b/gcc/testsuite/g++.dg/template/ref8.C new file mode 100644 index 0000000..a2fc847 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ref8.C @@ -0,0 +1,8 @@ +// PR c++/60222 + +template struct A +{ + template struct B; + + template struct B {}; +};