From patchwork Tue Oct 9 15:26:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 190350 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]) by ozlabs.org (Postfix) with SMTP id BC59A2C00BD for ; Wed, 10 Oct 2012 02:26:39 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1350401200; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Cc:Subject:References:Date:In-Reply-To: Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=HQN8FymQ/p5x1/n6sWFgT3Ls4og=; b=a8IYjXCICwJi/kgkLlLa9Ol5eJobCowhZin47jy6wDQAZgDWcYkCLpJJSyHKbT 11lNFOsFHrTUzdrQL5zcNb/DswRxIBGqUrc8FbkjnQpLPV1m3UCbB2pKOzfnafow FwsK2xphqWrBNPWg/T5U5n3eueO3sxrA0u872y3eR24NU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:From:To:Cc:Subject:References:X-URL:Date:In-Reply-To:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=B8GPNYFMXhUGb9TWFE6oINo2StkG6olxY2GznbTYCHYfioOe9fhyNJNwHeOGSO X3pQXd+1DAz0Q2i/a0Xghko+80g7ibtHZhQrT40pSs9d3LMWbpJkHdTFst6ydqmA KbXwEGISOpvYgAmZi55eNJLNNDGk7zvZVNqdPGsJA8L44=; Received: (qmail 19872 invoked by alias); 9 Oct 2012 15:26:35 -0000 Received: (qmail 19818 invoked by uid 22791); 9 Oct 2012 15:26:33 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 09 Oct 2012 15:26:21 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q99FQKWh027102 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 9 Oct 2012 11:26:21 -0400 Received: from localhost (ovpn-116-71.ams2.redhat.com [10.36.116.71]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q99FQJvu030506 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 9 Oct 2012 11:26:20 -0400 Received: by localhost (Postfix, from userid 1000) id C820F2C007C; Tue, 9 Oct 2012 17:26:18 +0200 (CEST) From: Dodji Seketeli To: Jason Merrill Cc: GCC Patches Subject: Re: [PATCH] PR c++/53540 - using fails to be equivalent to typedef References: <50731EA4.7020106@redhat.com> X-URL: http://www.redhat.com Date: Tue, 09 Oct 2012 17:26:18 +0200 In-Reply-To: <50731EA4.7020106@redhat.com> (Jason Merrill's message of "Mon, 08 Oct 2012 14:42:44 -0400") Message-ID: <87d30rbrad.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) MIME-Version: 1.0 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 Jason Merrill writes: > Let's move the alias template case from > primary_template_instantiation_p into alias_template_specialization_p > and call the latter from the former. And also call it from tsubst. Like the below? Note that I have changed the type of the argument of alias_template_specialization_p to const_tree to comply with the constness of the argument of primary_template_instantiation_p. Tested on x86_64-unknown-linux-gnu against trunk. gcc/cp * cp-tree.h (TYPE_TEMPLATE_INFO): For an alias that is not an instance of alias template, don't look for its TEMPLATE_INFO in its declaration. (alias_template_specialization_p): Take const_tree. * pt.c (alias_template_specialization_p): Take a const_tree. Don't call primary_template_instantiation_p. (primary_template_instantiation_p): Call alias_template_specialization_p. gcc/testsuite/ * g++.dg/cpp0x/alias-decl-24.C: New test. --- gcc/cp/cp-tree.h | 6 +++--- gcc/cp/pt.c | 17 +++++++---------- gcc/testsuite/g++.dg/cpp0x/alias-decl-24.C | 24 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-24.C diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 370f072..35819ed 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -2646,8 +2646,8 @@ extern void decl_shadowed_for_var_insert (tree, tree); template info for the alias template, not the one (if any) for the template of the underlying type. */ #define TYPE_TEMPLATE_INFO(NODE) \ - (TYPE_ALIAS_P (NODE) \ - ? ((TYPE_NAME (NODE) && DECL_LANG_SPECIFIC (TYPE_NAME (NODE))) \ + ((TYPE_ALIAS_P (NODE) && DECL_LANG_SPECIFIC (TYPE_NAME (NODE))) \ + ? (DECL_LANG_SPECIFIC (TYPE_NAME (NODE)) \ ? DECL_TEMPLATE_INFO (TYPE_NAME (NODE)) \ : NULL_TREE) \ : ((TREE_CODE (NODE) == ENUMERAL_TYPE) \ @@ -5437,7 +5437,7 @@ extern bool reregister_specialization (tree, tree, tree); extern tree fold_non_dependent_expr (tree); extern tree fold_non_dependent_expr_sfinae (tree, tsubst_flags_t); extern bool alias_type_or_template_p (tree); -extern bool alias_template_specialization_p (tree); +extern bool alias_template_specialization_p (const_tree); extern bool explicit_class_specialization_p (tree); extern int push_tinst_level (tree); extern void pop_tinst_level (void); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 1377b3e..d81626c 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -2929,10 +2929,7 @@ primary_template_instantiation_p (const_tree t) else if (CLASS_TYPE_P (t) && !TYPE_DECL_ALIAS_P (TYPE_NAME (t))) return CLASSTYPE_TEMPLATE_INSTANTIATION (t) && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)); - else if (TYPE_P (t) - && TYPE_TEMPLATE_INFO (t) - && PRIMARY_TEMPLATE_P (TYPE_TI_TEMPLATE (t)) - && DECL_TEMPLATE_INSTANTIATION (TYPE_NAME (t))) + else if (alias_template_specialization_p (t)) return true; return false; } @@ -5077,11 +5074,14 @@ alias_type_or_template_p (tree t) /* Return TRUE iff is a specialization of an alias template. */ bool -alias_template_specialization_p (tree t) +alias_template_specialization_p (const_tree t) { if (t == NULL_TREE) return false; - return (primary_template_instantiation_p (t) + + return (TYPE_P (t) + && TYPE_TEMPLATE_INFO (t) + && PRIMARY_TEMPLATE_P (TYPE_TI_TEMPLATE (t)) && DECL_ALIAS_TEMPLATE_P (TYPE_TI_TEMPLATE (t))); } @@ -10945,10 +10945,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) { tree decl = TYPE_NAME (t); - if (TYPE_DECL_ALIAS_P (decl) - && DECL_LANG_SPECIFIC (decl) - && DECL_TEMPLATE_INFO (decl) - && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl))) + if (alias_template_specialization_p (t)) { /* DECL represents an alias template and we want to instantiate it. */ diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-24.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-24.C new file mode 100644 index 0000000..b68fa93 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-24.C @@ -0,0 +1,24 @@ +// Origin: PR c++/53540 +// { dg-do compile { target c++11 } } + +template +struct context +{ + typedef int type; +}; + +template +void function() +{ + using ctx1 = context; + typename ctx1::type f1; + + typedef context ctx2; + typename ctx2::type f2; +} + +int main() +{ + function(); +} +